#P2950. [USACO09OPEN] Bovine Embroidery G

    ID: 1991 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划,dp递推2009USACO单调队列

[USACO09OPEN] Bovine Embroidery G

Description

Bessie has taken up the detailed art of bovine embroidery. Cows embroider a cloth mounted in a circular hoop of integer radius dd (1d500001 \le d \le 50000). They sew NN (2N500002 \le N \le 50000) straight threads, each from one point on the edge of the hoop to another point on the edge (no two embroidered points share a location on the hoop's edge).

Being mathematically inclined, Bessie knows a formula of the form ax+by+c=0ax + by + c = 0 for each straight thread. Conveniently, aa, bb, and cc are integers (1000000a1000000-1000000 \le a \le 1000000, 1000000b1000000-1000000 \le b \le 1000000, 1000000c1000000-1000000 \le c \le 1000000). Even more conveniently, no two threads coincide exactly. At least one of aa and bb is non-zero for each thread’s formula.

Perhaps less conveniently, Bessie knows that her set of formula coefficients also includes some lines that do not pass through the interior of the hoop’s circle. The origin (0,0)(0, 0) is at the exact center of the hoop, so all points on the hoop’s edge are at distance dd from the origin.

Bovine embroidery is more highly regarded when the number of thread intersections is maximized. Help Bessie count the number of pairs of threads that intersect on the cloth, i.e., whose intersection point lies within distance dd of the origin. If kk threads meet at the same point inside the circle, they contribute (k2)\binom{k}{2} pairs (e.g., three threads give three pairs; four threads give six pairs).

Input Format

  • Line 1: Two space-separated integers NN and dd.
  • Lines 2 to N+1N+1: Line i+1i+1 describes thread ii with three integers: aa, bb, and cc.

Output Format

  • Line 1: One integer, the count of pairs of threads that intersect inside the circle of radius dd.
2 1 
1 0 0 
0 1 0 

1 

Hint

The two lines are x=0x = 0 and y=0y = 0. The two lines intersect at (0,0)(0, 0), which is clearly within distance 11 of the origin.

Translated by ChatGPT 5