304012: CF771F. Bear and Isomorphic Points

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Bear and Isomorphic Points

题意翻译

给定 $n$ 个点 $(x_1, y_1), (x_2, y_2), \cdots, (x_n, y_n)$。 已知点 $P(x_0, y_0)$ 满足: - $\forall 2 \leqslant i < j \leqslant n$,点 $(x_1, y_1)$ 和点 $P$ 在经过 $(x_i, y_i), (x_j, y_j)$ 的直线的同侧。 若 $\lvert x_0 \rvert, \lvert y_0 \rvert \leqslant 10^6$,求点 $P$ 满足条件的概率乘以 $4 \times 10^{12}$ 的值。 保证数据组数不超过 $500$ 且 $\sum n \leqslant 2 \times 10^5$。

题目描述

Bearland is a big square on the plane. It contains all points with coordinates not exceeding $ 10^{6} $ by the absolute value. There are $ n $ houses in Bearland. The $ i $ -th of them is located at the point $ (x_{i},y_{i}) $ . The $ n $ points are distinct, but some subsets of them may be collinear. Bear Limak lives in the first house. He wants to destroy his house and build a new one somewhere in Bearland. Bears don't like big changes. For every three points (houses) $ p_{i} $ , $ p_{j} $ and $ p_{k} $ , the sign of their cross product $ (p_{j}-p_{i})×(p_{k}-p_{i}) $ should be the same before and after the relocation. If it was negative/positive/zero, it should still be negative/positive/zero respectively. This condition should be satisfied for all triples of indices $ (i,j,k) $ , possibly equal to each other or different than $ 1 $ . Additionally, Limak isn't allowed to build the house at the point where some other house already exists (but it can be the point where his old house was). In the formula above, we define the difference and the cross product of points $ (a_{x},a_{y}) $ and $ (b_{x},b_{y}) $ as: $ (a_{x},a_{y})-(b_{x},b_{y})=(a_{x}-b_{x},a_{y}-b_{y}), $ $ (a_{x},a_{y})×(b_{x},b_{y})=a_{x}·b_{y}-a_{y}·b_{x}. $ Consider a set of possible new placements of Limak's house. Your task is to find the area of that set of points. Formally, let's say that Limak chooses the new placement randomly (each coordinate is chosen independently uniformly at random from the interval $ [-10^{6},10^{6}] $ ). Let $ p $ denote the probability of getting the allowed placement of new house. Let $ S $ denote the area of Bearland ( $ S=4·10^{12} $ ). Your task is to find $ p·S $ .

输入输出格式

输入格式


The first line of the input contains an integer $ T $ ( $ 1<=T<=500 $ ) — the number of test cases. The description of the test cases follows. The first line of the description of a test case contains an integer $ n $ ( $ 3<=n<=200000 $ ) — the number of houses. The $ i $ -th of the next $ n $ lines contains two integers $ x_{i} $ and $ y_{i} $ ( $ -10^{6}<=x_{i},y_{i}<=10^{6} $ ) — coordinates of the $ i $ -th house. No two houses are located at the same point in the same test case. Limak lives in the first house. The sum of $ n $ won't exceed $ 200000 $ .

输出格式


Print one real value, denoting the area of the set of points that are possible new placements of Limak's house. Your answer will be considered correct if its absolute or relative error doesn't exceed $ 10^{-6} $ . More precisely, let the jury's answer be $ b $ , and your answer be $ a $ . Then your answer will be accepted if and only if ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF771F/72367bbd0f6e801440a3fd0f0493afeb00a874c1.png).

输入输出样例

输入样例 #1

4
4
5 3
0 1
10 1
3 51
3
-999123 700000
-950000 123456
-950000 987654
3
2 3
10 -1
-4 6
5
1 3
5 2
6 1
4 4
-3 3

输出样例 #1

250.000000000000
100000000000.000000000000
0.000000000000
6.562500000000

说明

In the sample test, there are $ 4 $ test cases. In the first test case, there are four houses and Limak's one is in $ (5,3) $ . The set of valid new placements form a triangle with vertices in points $ (0,1) $ , $ (10,1) $ and $ (3,51) $ , without its sides. The area of such a triangle is $ 250 $ . In the second test case, the set of valid new placements form a rectangle of width $ 50000 $ and height $ 2000000 $ . Don't forget that the new placement must be inside the big square that represents Bearland. In the third test case, the three given points are collinear. Each cross product is equal to $ 0 $ and it should be $ 0 $ after the relocation as well. Hence, Limak's new house must lie on the line that goes through the given points. Since it must also be inside the big square, new possible placements are limited to some segment (excluding the two points where the other houses are). The area of any segment is $ 0 $ .

Input

题意翻译

给定 $n$ 个点 $(x_1, y_1), (x_2, y_2), \cdots, (x_n, y_n)$。 已知点 $P(x_0, y_0)$ 满足: - $\forall 2 \leqslant i < j \leqslant n$,点 $(x_1, y_1)$ 和点 $P$ 在经过 $(x_i, y_i), (x_j, y_j)$ 的直线的同侧。 若 $\lvert x_0 \rvert, \lvert y_0 \rvert \leqslant 10^6$,求点 $P$ 满足条件的概率乘以 $4 \times 10^{12}$ 的值。 保证数据组数不超过 $500$ 且 $\sum n \leqslant 2 \times 10^5$。

加入题单

上一题 下一题 算法标签: