CF1381E.Origami
普及/提高-
通过率:0%
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 n 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=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 q independent queries for values f1,…,fq .
输入格式
The first line contains two integers n , q ( 3≤n≤105,1≤q≤105 ) — the number of polygon vertices and queries, respectively.
Each of the next n lines contains two integers xi , yi ( ∣xi∣,∣yi∣≤105 ) — the coordinates of the i -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) and (xn,yn) . 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 q lines contains a single integer fi ( j=1minn(xj)<fi<j=1maxn(xj) ) — the x -coordinate of the i -th fold query. It is guaranteed that all fi are distinct.
输出格式
For each query, output the area Ai of the paper if you fold it along the line x=fi .
Your answer is considered correct if its absolute or relative error does not exceed 10−4 .
Formally, let your answer be a , and the jury's answer be b . Your answer is accepted if and only if max(1,∣b∣)∣a−b∣≤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=−5 :
The second test, with the fold f=1 :
The third test, with the fold f=−1 :