POJ 2653 Pick-up Sticks

Source: Internet
Author: User

Calculate geometry to determine intersection of segments

Note the sentence in the title: You could assume that there is no more than top sticks.

I think it is not described clearly, if not every time the throw is guaranteed not more than 1000, the problem is very difficult to do.

If each throw is guaranteed to be less than 1000 root at the top, then violence can be.

Open a vector to save each throw at the top of the stick, the next time you throw, as long as the removal of the vector and throw in the intersection of the stick, and then put the stick into the, and finally left is the answer

#include <cstdio>#include<cstring>#include<vector>#include<cmath>#include<queue>#include<list>#include<algorithm>using namespacestd;Const intmaxn=100000+Ten;Const Doubleeps=1e-8;intTotp,totl;structpoint{Doublex; Doubley;} p[2*MAXN];structline{Point A;    Point B; intID;} Line[maxn];vector<Line>V;vector<Line>:: Iterator Iter;vector<int>ans;intFLAG[MAXN];DoubleXmult (Point p1,point p2,point p0) {return(p1.x-p0.x) * (P2.Y-P0.Y)-(p2.x-p0.x) * (p1.y-p0.y);}intopposite_side (Point p1,point p2,point l1,point L2) {returnXmult (L1,P1,L2) *xmult (L1,P2,L2) <-EPS;}intintersect_ex (Point u1,point u2,point v1,point v2) {returnOpposite_side (U1,U2,V1,V2) &&opposite_side (V1,V2,U1,U2);}intMain () { while(~SCANF ("%d",&Totl)) {        if(!TOTL) Break; TotP=0;  for(intI=0; i<totl; i++)        {            Doublea,b,c,d; scanf ("%LF%LF%LF%LF",&a,&b,&c,&d); P[TOTP+0].x=A; P[TOTP+0].y=b; P[TOTP+1].x=C; P[TOTP+1].y=D; LINE[I].A=p[totp+0]; LINE[I].B=p[totp+1]; Line[i].id=i; TotP=totp+2;        } v.clear ();  for(intI=0; i<totl; i++)        {             for(Iter=v.begin (); iter!=v.end ();) { line now=*Iter; if(INTERSECT_EX (line[i].a,line[i].b,now.a,now.b)) Iter=v.erase (Iter); Elseiter++;        } v.push_back (Line[i]);        } ans.clear ();  for(Iter=v.begin (); Iter!=v.end (); iter++) { line now=*Iter;        Ans.push_back (now.id); } printf ("Top Sticks:");  for(intI=0; I<ans.size (); i++) {printf ("%d", ans[i]+1); if(I<ans.size ()-1) printf (", "); Elseprintf". \ n"); }    }    return 0;}

POJ 2653 Pick-up Sticks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.