CF799G.Cut the pie
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Arkady reached the n-th level in Township game, so Masha decided to bake a pie for him! Of course, the pie has a shape of convex n-gon, i.e. a polygon with n vertices.
Arkady decided to cut the pie in two equal in area parts by cutting it by a straight line, so that he can eat one of them and give the other to Masha. There is a difficulty because Arkady has already put a knife at some point of the pie, so he now has to cut the pie by a straight line passing trough this point.
Help Arkady: find a line that passes through the point Arkady has put a knife into and cuts the pie into two parts of equal area, or determine that it's impossible. Your program has to quickly answer many queries with the same pie, but different points in which Arkady puts a knife.
阿尔卡季在《小镇》游戏中达到了第 n 级,因此玛莎决定为他烤一个派!当然,这个派的形状是一个凸 n 边形,即具有 n 个顶点的凸多边形。
阿尔卡季打算用一条直线将派切成面积相等的两部分,以便他自己吃其中一份,另一份送给玛莎。但存在一个困难:阿尔卡季已将刀尖放在派上的某个位置,因此他现在必须沿一条经过该点的直线来切派。
请帮助阿尔卡季:找出一条经过阿尔卡季放置刀尖位置的直线,使得该直线将派分成面积相等的两部分;若不存在这样的直线,则判定其不可能。你的程序需要对同一个派(即固定多边形)快速回答多个查询,每个查询给出阿尔卡季放置刀尖的不同位置。
输入格式
The first line contains two integers n and q (3 ≤ n ≤ 104, 1 ≤ q ≤ 105) — the number of vertices in the pie and the number of queries.
n line follow describing the polygon vertices in clockwise order. The i-th of these line contains two integers x__i and y__i ( - 106 ≤ x__i, y__i ≤ 106) — the coordinates of the i-th vertex. It is guaranteed that the polygon is strictly convex, in particular, no three vertices line on the same line.
An empty line follows.
q lines follow describing the query points. The i-th of these lines contain two integers x__i and y__i ( - 106 ≤ x__i, y__i ≤ 106) — the coordinates of the point in which Arkady puts the knife in the i-th query. In is guaranteed that in each query the given point is strictly inside the polygon, in particular, is not on its edges.
第一行包含两个整数 n 和 q(3≤n≤104,1≤q≤105)—— 分别表示饼图(多边形)的顶点数和查询次数。
接下来 n 行按顺时针顺序描述多边形的顶点。其中第 i 行包含两个整数 xi 和 yi(−106≤xi,yi≤106)—— 表示第 i 个顶点的坐标。保证该多边形是严格凸的,特别地,任意三个顶点不共线。
随后是一空行。
接下来 q 行描述查询点。其中第 i 行包含两个整数 xi 和 yi(−106≤xi,yi≤106)—— 表示 Arkady 在第 i 次查询中下刀的位置坐标。保证每次查询所给的点严格位于多边形内部,特别地,不在其任何一条边上。
输出格式
For each query print single integer — the polar angle of the line that is the answer for the corresponding query, in radians. The angle should be in the segment [0;π], the angles are measured from the direction of OX axis in counter-clockwise order. For example, the polar angle of the OY axis is
. If there is no answer in that query, print -1.
If there are several answers, print any of them. Your answer is considered correct if the difference between the areas of the parts divided by the total area of the polygon doesn't exceed 10 - 4 by absolute value. In other words, if a and b are the areas of the parts after the cut, then your answer is correct if and only of
.
对于每个查询,输出一个整数——即对应查询答案直线的极角(以弧度为单位)。该角度应在区间 [0;π] 内,且从 OX 轴正方向起按逆时针方向测量。例如,OY 轴的极角为
。若该查询无解,则输出 −1。
若存在多个可行解,输出任意一个即可。当所划分两部分面积与多边形总面积之比的差值的绝对值不超过 10−4 时,你的答案即被视为正确。换言之,若切割后两部分面积分别为 a 和 b,则你的答案正确当且仅当
。
输入输出样例
输入#1
3 1 0 0 0 3 3 0 1 1
输出#1
2.67794504460098710000
输入#2
5 3 6 5 6 3 5 0 0 0 0 5 5 4 3 3 5 2
输出#2
0.60228734612690049000 1.27933953226473580000 2.85805511179015910000
输入解题思路,AI测评打分。不知道怎么写?