| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 4 초 | 1024 MB | 230 | 116 | 91 | 49.189% |
For millenia, people have been interested in approximating $\pi$. One famous method is known as Buffon's Needle: drop a bunch of needles of length 1ドル$ on a coordiate plane with a vertical line drawn at each integer $x$ coordinate (so there are lines $x = 0,ドル $x = 1,ドル $x = -1,ドル and so on). Each needle either intersects a vertical line, or lies entirely between two vertical lines. It turns out that, if the needles are dropped randomly, the fraction of needles that intersect a vertical line can be used to approximate $\pi$! (The specific assumptions about exactly how the needles are dropped in the experiment are not important for this problem.)
In particular, let $x$ be the fraction of needles that intersect a vertical line. Then
$$\pi \approx \frac{2}{x}.$$
You are given the positions of $N$ needles (not necessarily random), and it is guaranteed that at least one of them intersects a vertical line. What is the corresponding approximation of $\pi,ドル using the above formula?
The first line of input contains a single integer $N$ (1ドル \leq N \leq 10^4$), the number of needles. $N$ lines follow.
The $i$-th such line describes the $i$-th needle. It contains four real numbers: $x_{i1}, y_{i1}, x_{i2}, y_{i2}$. This means that the $i$-th needle has one endpoint at $(x_{i1}, y_{i1})$ in the plane and the other endpoint at $(x_{i2}, y_{i2})$.
All real numbers in the input are given with exactly 6ドル$ digits after the decimal point and have absolute value at most 10ドル$. Furthermore, it is guaranteed that no $x$ coordinates in the input are within 10ドル^{-6}$ of an integer.
Since all the needles are of length 1ドル,ドル for each $i$ it is guaranteed that
$$|(x_{i1} - x_{i2})^2 + (y_{i1} - y_{i2})^2 - 1| < 10^{-3}.$$
Output a single real number, the approximation of $\pi$ described above. Your answer is considered correct if its absolute or relative error is at most 10ドル^{-6}$.
2 0.500000 0.500000 1.500000 0.500000 0.400000 -0.200000 0.600000 0.779796
4.000000000000
2 0.500000 0.500000 1.500000 0.500000 2.250000 0.000000 1.542893 0.707107
2.000000000000
In the first sample, the first needle intersects a vertical line ($x = 1$), but the second doesn't. So the fraction of needles that intersect vertical lines is 1ドル/2$ and the corresponding approximation of $\pi$ is 4ドル$.
In the second sample, both the needles intersect vertical lines ($x = 1$ and $x = 0$), so the fraction of needles that intersect vertical lines is 1ドル$ and the corresponding approximation of $\pi$ is 2ドル$.
University > UT Invitational Programming Contest > UT Invitational Programming Contest 2019 K번