问题 B: Stillwater Prison

内存限制:128 MB 时间限制:6 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

In the problem H of BCPC 2020 Final, Mocha had used most of her magic to protect Arad mainland. After that, Mocha tried to go back to her own world by travel magic. However, Mocha spent so much magic to protect Arad mainland that she can’t maintain mana stability during travel. As a result, Mocha found she woubld be transported into the Stillwater Prison!
The magic is forbidden in the Stillwater Prison, so Mocha wants to escape the Stillwater Prison as soon as possible. The Stillwater Prison can be regard as a convex polygon in an infinite two-dimensional plane. Mocha will be transported to some point PPP which is strictly inside the polygon. Mocha will choose one point QQQ which is on the edge of the polygon (QQQ can also be some vertice of the polygon), then she will move from point PPP to point QQQ along the segment PQPQPQ.
Mocha is too anxious to calm down and calculate. Please help her to calculate the minimum distance she needs to move to escape the Stillwater Prison. Since Mocha can’t confirm where she will be transported, you need to answer multiple queries.

输入格式


The first line contains one integer nnn (3≤n≤1053\leq n\leq 10^53n105), indicating the number of vertices of the convex polygon.
In the next nnn lines, each line contains two integers x,yx,yx,y (−109≤x,y≤109-10^9\leq x,y\leq 10^9109x,y109), indicating the coordinates of the vertices of the convex polygon. The coordinates of the vertices are given in counterclockwise order.
The next line contains one integer qqq (1≤q≤1051\leq q\leq 10^51q105), indicating the number of queries.
In the next qqq lines, each line contains two integers Px,PyP_x,P_yPx,Py (−109≤Px,Py≤109-10^9\leq P_x,P_y\leq 10^9109Px,Py109), indicating the coordinate of the point PPP where Mocha will be transported to. It’s guaranteed that PPP is strictly inside the polygon.

输出格式


For each query, print a real number in a single line, indicating the minimum distance she needs to move to escape the Stillwater Prison. Your answer will be considered correct if its relative or absolute error does not exceed 10−610^{-6}106.

输入样例 复制

3
-10 -10
1000 2
0 11515
3
1 1
250 500
700 600

输出样例 复制

10.8685398419
259.5573860250
247.1282543552