链接:https://www.nowcoder.com/acm/contest/141/J
来源:牛客网
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 262144K,其他语言524288K
Special Judge, 64bit IO Format: %lld
题目描述
Eddy has graduated from college. Currently, he is finding his future job and a place to live. Since Eddy is currently living in Tien-long country, he wants to choose a place inside Tien-long country to live. Surprisingly, Tien-long country can be represented as a simple polygon on 2D-plane. More surprisingly, Eddy can choose any place inside Tien-long country to live. The most important thing Eddy concerns is the distance from his place to the working place. He wants to live neither too close nor too far to the working place. The more specific definition of "close" and "far" is related to working place.
Eddy has M choices to work in the future. For each working place, it can be represented as a point on 2D-plane. And, for each working place, Eddy has two magic parameters P and Q such that if Eddy is going to work in this place, he will choose a place to live which is closer to the working place than portion of all possible living place choices.
Now, Eddy is wondering that for each working place, how far will he lives to the working place. Since Eddy is now busy on deciding where to work on, you come to help him calculate the answers.
For example, if the coordinates of points of Tien-long country is (0,0), (2,0), (2, 2), (0, 2) in counter-clockwise order. And, one possible working place is at (1,1) and P=1, Q=2. Then, Eddy should choose a place to live which is closer to (1, 1) than half of the choices. The distance from the place Eddy will live to the working place will be about 0.7978845608.
输入描述:
The first line contains one positive integer N indicating the number of points of the polygon representing Tien-long country. Each of following N lines contains two space-separated integer (xi, yi) indicating the coordinate of i-th points. These points is given in clockwise or counter-clockwise order and form the polygon. Following line contains one positive integer M indicating the number of possible working place Eddy can choose from. Each of following M lines contains four space-separated integer xj, yj, P, Q, where (xj, yj) indicating the j-th working place is at (xj, yj) and magic parameters is P and Q. 3 ≤ N ≤ 200 1 ≤ M ≤ 200 1 ≤ P < Q ≤ 200 |xi|, |yi|, |xj|, |yj| ≤ 103 It's guaranteed that the given points form a simple polygon.
输出描述:
Output M lines. For i-th line, output one number indicating the distance from the place Eddy will live to the i-th working place. Absolutely or relatively error within 10-6 will be considered correct.
示例1
输入
4 0 0 2 0 2 2 0 2 1 1 1 1 2
输出
0.797884560809
示例2
输入
3 0 0 1 0 2 1 2 0 0 1 2 1 1 1 3
输出
1.040111537176 0.868735603376
因为工作地点的原因,Eddy想在Tien-long country找一个地方作为家,但是Eddy不想理工作地点太远或者太近,因此他给出了一个P和Q,设以工作地点为中心的圆与Tien-long country交面积为S1,Tien-long country面积为S2,那么有(S2-S1)/S2=P/Q。
而Eddy想住在满足这样的P,Q的以工作地点为中心的圆的轨迹与Tien-long country的交线上。
现在给出Tien-long country的点表示多边形,和多个工作地点的坐标和P,Q,求Eddy能住在离工作地点多远的地方。
实际上就是求满足条件下圆的半径,这样我们只要二分答案套上多边形和圆的交面积模板就行了。
不过这里精度比较卡人,eps最好开到1e-12,并且都用long double;或者先用int存储到最后计算时才转成double。
#include
#include
#include
#include
#include