[Cpp]
/*
Question: Then I threw some sticks and output the numbers of the sticks (no sticks pressed) at the top.
Line Segment Intersection
Vector is used in the ontology.
Note the usage of v. erase (remove_if (v. begin (), v. end (), OK), v. end ();
At the same time, v. erase returns the location of the next element after deletion. Do not use it ++ to operate the next element in the loop.
*/
# Include <stdio. h>
# Include <vector>
# Include <algorithm>
Using namespace std;
Const double esp = 1e-8;
Struct point
{
Double x, y;
};
Struct node
{
Point p1, p2;
Int no;
};
Vector <node> v;
Int n;
Node cc;
Double max (double a, double B) {return a> B? A: B ;}
Double min (double a, double B) {return a <B? A: B ;}
Double cross (point p, point s, point e)
{
Return (e. x-s.x) * (p. y-s.y)-(p. x-s.x) * (e. y-s.y );
}
Bool segintersect (point s1, point e1, point s2, point e2)
{
Return (max (s1.x, e1.x)> = min (s2.x, e2.x ))&&
(Max (s2.x, e2.x)> = min (s1.x, e1.x ))&&
(Max (s1.y, e1.y)> = min (s2.y, e2.y ))&&
(Max (s2.y, e2.y)> = min (s1.y, e1.y ))&&
(Cross (s1, s2, e2) * cross (e1, s2, e2) <= esp )&&
(Cross (s2, s1, e1) * cross (e2, s1, e1) <= esp ));
}
Bool OK (node n)
{
If (segintersect (n. p1, n. p2, cc. p1, cc. p2 ))
Return true;
Return false;
}
Int main ()
{
Int I;
While (scanf ("% d", & n), n)
{
V. erase (v. begin (), v. end ());
For (I = 1; I <= n; I ++)
{
Scanf ("% lf", & cc. p1.x, & cc. p1.y, & cc. p2.x, & cc. p2.y );
Cc. no = I;
V. erase (remove_if (v. begin (), v. end (), OK), v. end ());
V. push_back (cc );
}
Printf ("Top sticks :");
For (vector <node >:: iterator it = v. begin (); it! = V. end (); it ++)
{
Printf ("% d", it-> no );
If (it! = V. end ()-1)
Printf (",");
Else printf (". \ n ");
}
} Www.2cto.com
Return 0;
}
Author: qq172108805