Pick-up STICKS-POJ 2653 (segment intersection)

Source: Internet
Author: User

The main topic: there is a stick, in order to arrange, to get out of the above is not the stick pressed by other sticks ....

 Analysis: Can maintain a queue, if the stick is not pressed into the queue, if the judgment is pressed, let the pressure out of the queue, and finally put the stick in the queue, but not fast, the enumeration is the fastest ... It is said that there are no more than 1000 top sticks at any one time ..... It's hard to notice.  The code is as follows:=========================================================================================================== ==========================
#include <stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<math.h>using namespacestd;Const intMAXN = 1e5+7;Const DoubleEPS = 1e-8;structpoint{Doublex, y; Point (Doublex=0,Doubley=0): X (x), Y (y) {} pointoperator- (ConstPoint &t)Const{        returnPoint (X-t.x, yt.y); }    Double operator* (ConstPoint &t)Const{       DoubleAns = x*t.y-y*T.x; if(Ans > EPS)return 1; if(Fabs (ANS) < EPS)return 0; return-1; }};structsegment{Point A, B; Segment (Point A=0, point b=0): A (a), B (b) {}};BOOLIntersect (Segment A, segment B) {return(A.A-A.B) * (B.A-A.B) + (a.a-a.b) * (b.b-a.b) = =0;}intUSED[MAXN], ans[maxn];segment SEG[MAXN];BOOLFind (intKintN) {     for(inti=k+1; i<=n; i++)    {        if(Intersect (Seg[k], seg[i]) &&Intersect (Seg[i], seg[k]))return true; }    return false;}intMain () {intN;  while(SCANF ("%d", &n)! = EOF &&N) { for(intI=1; i<=n; i++) {scanf ("%LF%LF%LF%LF", &seg[i]. A.x, &seg[i]. A.Y, &seg[i]. b.x, &Seg[i].            B.Y); Used[i]=false; }        intk=0;  for(intI=1; i<=n; i++) {Used[i]=Find (i, N); if(!used[i]) ans[k++] =i; } printf ("Top Sticks:");  for(intI=0; i<k-1; i++) printf ("%d,", Ans[i]); printf ("%d.\n", ans[k-1]); }    return 0;}

Pick-up STICKS-POJ 2653 (segment intersection)

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.