CF1906D.Spaceship Exploration
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In The ICPC Galaxy, there exists a zone filled with asteroids that is unsafe to enter. The map of the galaxy is represented in a 2D Cartesian coordinate system. The zone is in the shape of an N -sided convex polygon. Each corner is numbered from 1 to N ; corner i is located at (Xi,Yi) . At any moment, you should not be inside this polygon; however, it is safe to touch the side of the polygon.
There are Q scenarios (numbered from 1 to Q ). In scenario j , you want to go from a starting point at (Aj,Bj) to an ending point at (Cj,Dj) . You will be riding on a special spaceship that can only travel in a straight line. First, you set the direction of the spaceship, then the spaceship will start traveling in that direction. During the travel, you are only allowed to change direction at most once. Changing direction means you stop the spaceship, set a new direction, and then start traveling again in the new direction.
For each scenario, determine the minimum distance required to travel without being inside of the zone at any moment, or report if it is impossible to reach the ending point.
输入格式
The first line consists of an integer N ( 3≤N≤100000 ).
Each of the next N lines consists of two integers Xi Yi ( −109≤Xi,Yi≤109 ). The points form a convex polygon in counterclockwise order. There are no three points which are collinear.
The following line consists of an integer Q ( 1≤Q≤100000 ).
Each of the next Q lines consists of four integers Aj Bj Cj Dj ( −109≤Aj,Bj,Cj,Dj≤109 ). There are no starting points and ending points inside the zone. However, it is possible for the starting point and the ending point to be at the side of the zone.
All the coordinates in the input are integers.
输出格式
For each scenario, output the answer in a single line.
If it is possible to reach the ending point without being inside the zone at any moment, then output the minimum distance required to travel. Otherwise, output -1.
Your answer is considered correct if its absolute error or relative error does not exceed 10−6 . Namely, if your answer is a and the jury's answer is b , then your answer is accepted if max(1,∣b∣)∣a−b∣≤10−6 .
输入输出样例
输入#1
5 0 2 2 0 4 0 4 4 2 4 5 6 1 6 3 2 5 0 0 3 5 3 -1 1 4 5 4 3 4 3 0
输出#1
2 5.6055512755 8.48528137422 4 -1
输入#2
4 -10 -9 10 -9 10 9 -10 9 2 0 10 0 -10 -10 -10 -10 -10
输出#2
200.9975124224 0
输入#3
8 -20 -10 10 -20 25 -15 35 -5 30 10 15 20 -25 15 -30 5 6 -15 -15 -15 20 -30 -5 30 15 25 20 -5 -20 -5 25 20 -20 -30 10 30 -10 -30 -50 50 0
输出#3
59.0857761929 103.2455532034 94.7213595500 101.5640991922 164.8528137424 94.3398113206
说明/提示
Explanation for the sample input/output #1
This sample is depicted in the following illustration.
During scenario 1 and 4 , you can directly go to the ending point without changing the direction.
During scenario 2 , you can go to (0,2) , then change direction to the ending point.
During scenario 3 , you can go to (6,2) , then change direction to the ending point.
During scenario 5 , it can be shown that it is impossible to reach the ending point.