POJ 2653 Pick-up Sticks (judging segment intersection)

Source: Internet
Author: User

Pick-up Sticks
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 11043 Accepted: 4119

Description

Stan has n sticks of various length. He throws them one at a time to the floor in a random. After finishing throwing, Stan tries to find the top sticks, that's these sticks such that there was no stick on top of th Em. Stan has noticed, the last thrown stick was always on top and he wants to know all the sticks that's on top. Stan sticks is very, very thin such that their thickness can be neglected.

Input

Input consists of a number of cases. The data for each case is start with 1 <= n <= 100000, and the number of the sticks for this case. The following n lines contain four numbers each, these numbers is the planar coordinates of the endpoints of one stick. The sticks is listed in the order in which Stan had thrown them. Assume that there is no more than top sticks. The input is ended by the case with N=0. This case is should not being processed.

Output

For each input case, print one line of output listing the top sticks in the format given in the sample. The top sticks should is listed in order in which they were thrown.

The below illustrates the first case from input.

Sample Input

51 1 4 22 3 3 11-2.0 8 41 4 8 23 3 6-2.030 0 1 11 0 2 12 0 3 10

Sample Output

Top Sticks:2, 4, 5.Top sticks:1, 2, 3.

Hint

Huge input,scanf is recommended.

Source

Waterloo Local 2005.09.17

This is very simple ~ Template Dafa Good ~

Test instructions: Multi-instance testing, each group of n segments, 0 end, to determine how many segments in all segments are not placed in the back line, the number of lines that are pressed to output their numbers (starting from 1),

The format of the output is described in the example ~

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstdlib>5#include <cstring>6#include <math.h>7#include <algorithm>8#include <cctype>9#include <string>Ten#include <map> One#include <Set> A #definell Long Long - using namespacestd; -  the Const DoubleEPS = 1e-8; - intSgnDoublex) - { -     if(Fabs (x) < EPS)return 0; +     if(X <0)return-1; -     Else return 1; + } A struct Point at { -     Doublex, y; - Point () {} -Point (Double_x,Double_y) -     { -x =_x; iny =_y; -     } toPointoperator-(ConstPoint &b)Const +     { -         returnPoint (X-b.x,y-b.y); the     } *     Double operator^(ConstPoint &b)Const $     {Panax Notoginseng         returnx*b.y-y*b.x; -     } the     Double  operator*(ConstPoint &b)Const +     { A         returnx*b.x + y*b.y; the     } + }; -  $ struct Line $ { - Point s,e; - Line () {} the Line (Point _s,point _e) -     {Wuyis =_s; theE =_e; -     } Wu }; - BOOLInter (line l1,line L2) About { $     return -Max (l1.s.x,l1.e.x) >= min (l2.s.x,l2.e.x) && -Max (l2.s.x,l2.e.x) >= min (l1.s.x,l1.e.x) && -Max (l1.s.y,l1.e.y) >= min (l2.s.y,l2.e.y) && AMax (l2.s.y,l2.e.y) >= min (l1.s.y,l1.e.y) && +SGN ((l2.s-l1.s) ^ (L1.E-L1.S)) *SGN ((l2.e-l1.s) ^ (L1.E-L1.S)) <=0&& theSGN ((L1.S-L2.S) ^ (L2.E-L2.S)) *SGN ((L1.E-L2.S) ^ (L2.E-L2.S)) <=0; - } $ BOOLvisit[100005]; theLine line[100005]; the intMainvoid) the { the     intN; -      while(SCANF ("%d",&N), N) in     { the         DoubleX1,x2,y1,y2; the         intsum =N; Aboutmemset (Visit,false,sizeof(visit)); the          for(inti =1; I <= N; i++) the         { thescanf"%LF%LF%LF%LF",&x1,&y1,&x2,&y2); +Line[i] =Line (Point (X1,y1), point (X2,y2)); -Visit[i] =true; the         }Bayi          for(inti =1; I <= N; i++) the         { the              for(intj = i +1; J <= N; J + +) -             { -                 if(Inter (Line[i],line[j])) the                 { theVisit[i] =false; thesum--; the                      Break; -                 } the             } the         } theprintf"Top Sticks:");94          for(inti =1; I <= N; i++) the         { the             if(Visit[i]) the             {98                 if(Sum! =1) About                 { -sum--;101printf"%d,", i);102                 }103                 Else104                 { theprintf"%d.\n", i);106sum =0;107                      Break;108                 }109             } the         }111     } the     return 0;113}

POJ 2653 Pick-up Sticks (judging 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.