CF1381E.Origami

NOI/NOI+/CTSC

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

After being discouraged by 13 time-limit-exceeded verdicts on an ugly geometry problem, you decided to take a relaxing break for arts and crafts.

There is a piece of paper in the shape of a simple polygon with nn vertices. The polygon may be non-convex, but we all know that proper origami paper has the property that any horizontal line intersects the boundary of the polygon in at most two points.

If you fold the paper along the vertical line x=fx=f, what will be the area of the resulting shape? When you fold, the part of the paper to the left of the line is symmetrically reflected on the right side.

Your task is to answer qq independent queries for values f1,…,fqf_1,\ldots,f_q.

在一道丑陋的计算几何题上连续遭遇 13 次“时间超限”判据后,你决定放松一下,做些美术与手工活动。

现有一张纸,其形状是一个具有 nn 个顶点的简单多边形。该多边形可能非凸,但我们都知道,合格的折纸用纸具有如下性质:任意一条水平线与多边形边界的交点至多为两个。

若你沿竖直线 x=fx=f 将纸折叠,那么折叠后所得图形的面积是多少?折叠时,纸张位于该直线左侧的部分将被对称地反射到右侧。

你的任务是回答 qq 个独立的查询,对应参数值 f1,…,fqf_1,\ldots,f_q。

输入格式

The first line contains two integers nn, qq (3≤n≤105,1≤q≤1053\le n\le 10^5, 1\le q\le 10^5) — the number of polygon vertices and queries, respectively.

Each of the next nn lines contains two integers xix_i, yiy_i (∣xi∣,∣yi∣≤105|x_i|, |y_i|\le 10^5) — the coordinates of the ii-th point of the polygon. The polygon has an edge connecting each pair of adjacent points in the input, and also an edge between (x1,y1)(x_1,y_1) and (xn,yn)(x_n,y_n). It is guaranteed that the polygon is non-degenerate and that any horizontal line intersects the boundary of the polygon in at most two points. In particular, no boundary edge is strictly horizontal. Two adjacent sides may be collinear.

Each of the next qq lines contains a single integer fif_i (min⁡j=1n(xj)<fi<max⁡j=1n(xj)\min\limits_{j=1}^n(x_j) \lt f_i \lt \max\limits_{j=1}^n(x_j)) — the xx-coordinate of the ii-th fold query. It is guaranteed that all fif_i are distinct.

第一行包含两个整数 nn、qq(3≤n≤105, 1≤q≤1053\le n\le 10^5,\ 1\le q\le 10^5)—— 分别表示多边形的顶点数和查询次数。

接下来的 nn 行,每行包含两个整数 xix_i、yiy_i(∣xi∣,∣yi∣≤105|x_i|, |y_i|\le 10^5)—— 表示多边形第 ii 个顶点的坐标。多边形的边界由输入中每对相邻顶点依次连接而成,并且还有一条边连接 (x1,y1)(x_1,y_1) 与 (xn,yn)(x_n,y_n)。保证该多边形是非退化的,且任意一条水平直线与多边形边界的交点至多有两个。特别地,边界上不存在严格水平的边。相邻的两条边可能共线。

接下来的 qq 行,每行包含一个整数 fif_i(min⁡j=1n(xj)<fi<max⁡j=1n(xj)\min\limits_{j=1}^n(x_j) \lt f_i \lt \max\limits_{j=1}^n(x_j))—— 表示第 ii 次折叠操作的 xx-坐标。保证所有 fif_i 互不相同。

输出格式

For each query, output the area AiA_i of the paper if you fold it along the line x=fix=f_i.

Your answer is considered correct if its absolute or relative error does not exceed 10−410^{-4}.

Formally, let your answer be aa, and the jury's answer be bb. Your answer is accepted if and only if ∣a−b∣max⁡(1,∣b∣)≤10−4\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}.

对于每个查询,请输出沿直线 x=fix=f_i 折叠纸张后所得纸张的面积 AiA_i。

若你的答案的绝对误差或相对误差不超过 10−410^{-4},则视为正确。

形式化地,设你的答案为 aa,评测组的答案为 bb。当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−4\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4} 时,你的答案被接受。

输入输出样例

  • 输入#1

    4 7
    0 10
    10 0
    0 -10
    -10 0
    -9
    -5
    -1
    0
    1
    5
    9

    输出#1

    199.0000000000
    175.0000000000
    119.0000000000
    100.0000000000
    119.0000000000
    175.0000000000
    199.0000000000
  • 输入#2

    4 1
    0 0
    0 2
    2 4
    2 2
    1

    输出#2

    3.0000000000
  • 输入#3

    9 4
    0 -3
    2 -2
    -1 -1
    0 4
    2 5
    1 6
    -2 3
    -1 1
    -3 0
    0
    -2
    -1
    1

    输出#3

    11.1250000000
    11.7500000000
    10.3446969697
    11.3333333333

说明/提示

The first test, with the fold f=−5f=-5:

The second test, with the fold f=1f=1:

The third test, with the fold f=−1f=-1:

第一次测试,折叠位置 f=−5f=-5:

第二次测试,折叠位置 f=1f=1:

第三次测试,折叠位置 f=−1f=-1:

输入解题思路,AI测评打分。不知道怎么写?

首页