eolymp
bolt
Спробуйте наш новий інтерфейс для відправки розв'язків
Задачі

Probability Through experiment

Probability Through experiment

\includegraphics{https://static.e-olymp.com/content/49/49270e28ebc371c9e6e548fe5edf6353526f0ecb.jpg} Mathematicians have often solved problems by just doing some simulation or experiments. For example, the value of \textbf{pi} () can be approximately determined by randomly plotting points in a square that inscribes a circle. Because if the square is a \textbf{250×250} square, then its area is \textbf{62500} and the area of the inscribed circle is\textbf{pi*1252=15625pi}. As the points are plotted randomly, so it can be assumed that number of points inside the circle and total number points plotted in the square is proportional to their respective area. So, in this way, the value of pi can approximately be determined by counting how many points are inside the circle (\textit{\textbf{Figure 1}}). The value of pi can even be determined using a more sophisticated experiment like the Buffon’s needle experiment (\textit{\textbf{Figure 2}}). \includegraphics{https://static.e-olymp.com/content/0a/0a12311f0f5b2dccc6a93f57aa9452f001041c86.jpg} \textit{\textbf{Figure 1}}: Pi approximation by counting the number of points inside the circle The two experiments mentioned above to approximately determine the value of pi could be simulated by writing a computer program very easily. It would have been nice to do this sort of experiment a lot of time (Say \textbf{1} billion billion) and get an almost perfect result but for lack of time we cannot do that in real life. In this problem, you will have to write a program that will help Professor Wu to perform a similar sort of experiment but this program may not be that straightforward. \includegraphics{https://static.e-olymp.com/content/a1/a1605828ede3aa7c31581597337c6750e0b4be5c.jpg} \textit{\textbf{Figure 2}}: Buffon’s needle experiment \includegraphics{https://static.e-olymp.com/content/78/78122e0a8f87f8628759d246165a739768cdfd20.jpg} \includegraphics{https://static.e-olymp.com/content/78/78122e0a8f87f8628759d246165a739768cdfd20.jpg} \includegraphics{https://static.e-olymp.com/content/b3/b3d96fa46e3f153735348a348f1e748f2422f156.jpg} Professor Neal Wu is trying to solve a classic problem using simulation: If three points are randomly plotted on the boundary of a circle, then what is the probability that they will be the three vertex of an acute triangle? Of course, this problem can be solved analytically and the result he gets is \textbf{0.25}. Now, he wants to verify this result through an experiment. The result can be found approximately by plotting three random points on a circle billions of times and counting how many times these three points form an acute triangle. The beauty of such an experiment (as mentioned above) is that if we increase the number of trials, the result will become even more accurate. But if Dr. Wu wants to repeat this process \textbf{1000} billion times, it will take \textbf{2} hours of time and if he wants to repeat it a billion billion times, it may take more than \textbf{200} years. Dr. Wu has discovered that this process can be sped up by using a different approach -- generate \textbf{n} random points on the boundary of a circle and they form triangles as vertices. How many of these triangles are acute triangles? If the number of acute triangle is \textbf{M} and let \textbf{N =} , then the desired probability is . So, given the \textbf{n} points on the boundary, you have to assist Dr. Wu by writing a very efficient program to find the number of acute triangles. \includegraphics{https://static.e-olymp.com/content/0a/0af9e25c8b376659c46015965aefa828b1b75617.jpg} \textit{\textbf{Figure 3}}: Example of a circle with given points on the boundary \InputFile The input file contains around \textbf{40} test cases. But most of the cases are not extreme, so the size of the input file is around \textbf{3} MB. The description of each test case is given below. Each case starts with two positive integers \textbf{n} (\textbf{0} < \textbf{n} ≤ \textbf{20000}) and \textbf{r} (\textbf{0} < \textbf{r} ≤ \textbf{500}). Here, \textbf{n} is the total of points on the circle boundary and \textbf{r} is the radius of the circle. The center of the circle is always at the origin (\textbf{0}, \textbf{0}). Each of the next \textbf{N} lines denotes the location of one point on the boundary of the circle. Each point is \textbf{P}, denoted by a floating-point number \textbf{θ} (\textbf{0.000} ≤ \textbf{θ} < \textbf{360.000}). This \textbf{θ} is actually the angle (expressed in degree) the point \textbf{P} creates at the center of the circle with the positive direction of \textbf{x}-axis. So the Cartesian coordinate of \textbf{P} is (\textbf{r*cos(θ)}, \textbf{r*sin(θ)}). Value of \textbf{θ} will always have exactly three digits after the decimal point. No two points will be at the same location. A line containing two zeroes terminates the input. This line should not be processed. \OutputFile \includegraphics{https://static.e-olymp.com/content/78/78122e0a8f87f8628759d246165a739768cdfd20.jpg} Each test case produces one line of output. This line contains the serial of output followed by an integer. This integer denotes how many of the triangles formed by these n points are actually acute triangles. \textit{\textbf{Note}}: \textbf{20000} points generated on the boundary of a circle can actually create \textbf{20000*19999*19998/6 ~1333} billion triangles. So, of experiment for \textbf{1333} billions can be done in, say, \textbf{0.5} second. Then experiments with \textbf{1} billion billion triangles can be done in around \textbf{100} hours only (In contrast to \textbf{200} years mentioned earlier) just by repeating this experiment. Also, if we put \textbf{1817120} points on the boundary of the circle, around \textbf{1} billion billion triangles are created, and the number of acute triangles within this large number of triangles can be computed within \textbf{5} minutes.
Ліміт часу 2 секунди
Ліміт використання пам'яті 64 MiB
Вхідні дані #1
4 71
234.600
33.576
20.375
84.908
7 7
11.586
114.435
248.411
108.640
287.629
150.224
340.481
0 0
Вихідні дані #1
Case 1: 2
Case 2: 12
Джерело ACM-ICPC Asia Hatyai Regional Programming Contest – November 16, 2012 – PSU, Hatyai