CF1906D.Spaceship Exploration

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:1024MB

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 NN-sided convex polygon. Each corner is numbered from 11 to NN; corner ii is located at (Xi,Yi)(X_i, Y_i). At any moment, you should not be inside this polygon; however, it is safe to touch the side of the polygon.

There are QQ scenarios (numbered from 11 to QQ). In scenario jj, you want to go from a starting point at (Aj,Bj)(A_j, B_j) to an ending point at (Cj,Dj)(C_j, D_j). 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.

在 ICPC 星系中,存在一个充满小行星的危险区域,不可进入。星系的地图以二维笛卡尔坐标系表示。该危险区域呈 NN 边凸多边形形状。各顶点编号为 11 至 NN;其中顶点 ii 位于 (Xi,Yi)(X_i, Y_i)。在任意时刻,你均不得位于该多边形内部;但允许恰好接触多边形的边界(即边)。

共有 QQ 个场景(编号为 11 至 QQ)。在场景 jj 中,你需要从起点 (Aj,Bj)(A_j, B_j) 出发,抵达终点 (Cj,Dj)(C_j, D_j)。你将乘坐一艘特殊飞船,该飞船仅能沿直线航行。首先,你设定飞船的航行方向,随后飞船即沿该方向开始航行。在航行过程中,你最多允许改变一次方向;所谓“改变方向”是指:先使飞船停止,再设定新的航行方向,然后重新启动飞船沿新方向航行。

对每个场景,请确定在全程不进入危险区域(即始终不在多边形内部)的前提下,所需的最短航行距离;若无法抵达终点,则报告为不可能。

输入格式

The first line consists of an integer NN (3≤N≤100 0003 \leq N \leq 100\,000).

Each of the next NN lines consists of two integers XiX_i YiY_i (−109≤Xi,Yi≤109-10^9 \leq X_i, Y_i \leq 10^9). The points form a convex polygon in counterclockwise order. There are no three points which are collinear.

The following line consists of an integer QQ (1≤Q≤100 0001 \leq Q \leq 100\,000).

Each of the next QQ lines consists of four integers AjA_j BjB_j CjC_j DjD_j (−109≤Aj,Bj,Cj,Dj≤109-10^9 \leq A_j, B_j, C_j, D_j \leq 10^9). 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.

第一行包含一个整数 NN(3≤N≤100 0003 \leq N \leq 100\,000)。

接下来的 NN 行,每行包含两个整数 XiX_i 和 YiY_i(−109≤Xi,Yi≤109-10^9 \leq X_i, Y_i \leq 10^9)。这些点按逆时针顺序构成一个凸多边形。不存在三点共线的情况。

接下来一行包含一个整数 QQ(1≤Q≤100 0001 \leq Q \leq 100\,000)。

接下来的 QQ 行,每行包含四个整数 AjA_j、BjB_j、CjC_j、DjD_j(−109≤Aj,Bj,Cj,Dj≤109-10^9 \leq A_j, B_j, C_j, D_j \leq 10^9)。所有线段的起点和终点均不在区域内部;但起点或终点可能恰好位于区域的边界上。

输入中的所有坐标均为整数。

输出格式

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−610^{-6}. Namely, if your answer is aa and the jury's answer is bb, then your answer is accepted if ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max(1, |b|)} \leq 10^{-6}.

对于每种情况,请在一行内输出答案。

如果可以在任何时刻都不进入该区域的情况下到达终点,则输出所需的最短行进距离;否则输出 −1-1。

当且仅当你的答案的绝对误差或相对误差不超过 10−610^{-6} 时,该答案被视为正确。即:若你的答案为 aa,评测机的标准答案为 bb,则当 ∣a−b∣max⁡(1,∣b∣)≤10−6\frac{|a - b|}{\max(1, |b|)} \leq 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 11 and 44, you can directly go to the ending point without changing the direction.

During scenario 22, you can go to (0,2)(0, 2), then change direction to the ending point.

During scenario 33, you can go to (6,2)(6, 2), then change direction to the ending point.

During scenario 55, it can be shown that it is impossible to reach the ending point.

样例输入/输出 #1 的说明

该样例如下图所示。

在情形 11 和 44 中,你可以不改变方向直接到达终点。

在情形 22 中,你可以先到达点 (0,2)(0, 2),然后改变方向驶向终点。

在情形 33 中,你可以先到达点 (6,2)(6, 2),然后改变方向驶向终点。

在情形 55 中,可以证明无法到达终点。

输入解题思路,AI测评打分。不知道怎么写?

首页