A13619 | Origami
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $f_1,\ldots,f_q$ .
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 $f_1,\ldots,f_q$ .
输入格式
The first line contains two integers $n$ , $q$ ( $3\le n\le 10^5, 1\le q\le 10^5$ ) — the number of polygon vertices and queries, respectively.
Each of the next $n$ lines contains two integers $x_i$ , $y_i$ ( $|x_i|, |y_i|\le 10^5$ ) — 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 $(x_1,y_1)$ and $(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 $q$ lines contains a single integer $f_i$ ( $\min\limits_{j=1}^n(x_j)< f_i< \max\limits_{j=1}^n(x_j)$ ) — the $x$ -coordinate of the $i$ -th fold query. It is guaranteed that all $f_i$ are distinct.
Each of the next $n$ lines contains two integers $x_i$ , $y_i$ ( $|x_i|, |y_i|\le 10^5$ ) — 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 $(x_1,y_1)$ and $(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 $q$ lines contains a single integer $f_i$ ( $\min\limits_{j=1}^n(x_j)< f_i< \max\limits_{j=1}^n(x_j)$ ) — the $x$ -coordinate of the $i$ -th fold query. It is guaranteed that all $f_i$ are distinct.
输出格式
For each query, output the area $A_i$ of the paper if you fold it along the line $x=f_i$ .
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 $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$ .
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 $\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=-5$ :
The second test, with the fold $f=1$ :
The third test, with the fold $f=-1$ :

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

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted