You can solve a geometry problem too
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 3077 accepted submission (s): 1452
Problem descriptionmany ry (ry) problems were designed in the ACM/ICPC. and now, I also prepare a geometry problem for this final exam. according to the experience of specified acmers, geometry problems are always much trouble, but this problem is very easy, after all we are now attending an exam, not a contest
Give you n (1 <= n <= 100) segments (line segment), please output the number of all intersections (intersection ). you shoshould count repeatedly if M (M> 2) segments intersect at the same point.
Note:
You can assume that two segments wocould not intersect at more than one point.
Inputinput contains multiple test cases. each test case contains a integer N (1 = n <= 100) in a line first, and then n lines follow. each line describes one segment with four float values X1, Y1, X2, Y2 which are coordinates of the segment's ending.
A test case starting with 0 terminates the input and this test case is not to be processed.
Outputfor each case, print the number of intersections, and one line one case.
Sample input2 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.00 3 0.00 0.00 1.00 1.00 0.00 1.00 1.00 0.000 0.00 0.00 1.00 0.00 0
Sample output1 3
Authorlcy
# Include <stdio. h>
# Include <math. h>
# Include <iostream>
Using Namespace STD;
Struct Line
{
Double X1, Y1, X2, Y2;
} Node [ 110 ];
Bool Solve (line A, line B)
{
If (. X1-b.x1) * (. y2-b.y1)-(. x2-b.x1) * (. y1-b.y1) * (. x1-b.x2) * (. y2-b.y2)-(. x2-b.x2) * (. y1-b.y2)> 0 ) Return False ;
If (B. x1-a.x1) * (B. y2-a.y1)-(B. x2-a.x1) * (B. y1-a.y1) * (B. x1-a.x2) * (B. y2-a.y2)-(B. x2-a.x2) * (B. y1-a.y2)> 0 ) Return False ;
Return True ;
}
Int Main ()
{
Int N;
While (Scanf ( " % D " , & N), n)
{
For ( Int I = 0 ; I <n; I ++) scanf ( " % Lf " , & Node [I]. X1, & node [I]. Y1, & node [I]. X2, & node [I]. Y2 );
Int Res = 0 ;
For ( Int I = 0 ; I <n; I ++)
{
For ( Int J = I + 1 ; J <n; j ++)
{
If (Solve (node [I], node [J]) RES ++;
}
}
Printf ( " % D \ n " , Res );
}
Return 0 ;
}