#P4034. [Code+#2] 寄蒜几盒

[Code+#2] 寄蒜几盒

Description

In the 2D plane, there are nn lines that partition the plane into regions. Given mm points, find the area of the region that contains each point.

A careful reader will notice that some regions have infinite area. The R-surnamed author has anticipated this and provides a real number LL. Four extra lines x=L,x=L,y=L,y=Lx = L, x = -L, y = L, y = -L bound a finite rectangular area, and all query points lie strictly inside this bounded region.

An even more careful reader will note that if a query point lies exactly on a line or extremely close to one, numerical error could severely affect the answer. The R-surnamed author has anticipated this as well: in the testdata, the distance from any query point to any line is greater than 10710^{-7}.

Input Format

Read from standard input.

The first line contains two positive integers n,mn, m and one positive real number LL.

The next nn lines each contain three real numbers A,B,CA, B, C, indicating a line with equation Ax+By+C=0Ax + By + C = 0.

The next mm lines, the ii-th line contains two real numbers xi,yix_i, y_i, which are the coordinates of the ii-th point.

Output Format

Write to standard output.

Output mm lines, each containing one real number. The number on the ii-th line is the area of the region containing the ii-th point. Print with two decimal places.

2 4 3
1 1 -1
-1 1 -1
0 2
-2 1
2 1
0 0
4.00
8.50
8.50
15.00

Hint

For 20%20\% of the testdata, n,m10n, m \le 10.

For 40%40\% of the testdata, n,m300n, m \le 300.

For 100%100\% of the testdata, n500,m100000n \le 500, m \le 100000.

For 100%100\% of the testdata, the absolute value of every input number is 107\le 10^7, and each input number has at most two decimal places.

From the CodePlus 2017 December Contest, proudly presented by the Student Algorithms and Contest Association of the Department of Computer Science and Technology, Tsinghua University.

Credit: idea/Ru Yizhong; setter/Ru Yizhong; testers/Chen Yu, Wang Yuzhong.

Git Repo: https://git.thusaac.org/publish/CodePlus201712

Thanks to Tencent for supporting this contest.

Translated by ChatGPT 5