Pick-up sticks (judging the intersection of two lines)

Source: Internet
Author: User

Pick-up Sticks
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 11335 Accepted: 4250

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.
The problem is to find a straight line that is not in line with other lines or on the top of other lines;
Judge the intersection, the two straight line of an endpoint to be judged;
Code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cmath>5#include <algorithm>6 #defineMem (x, y) memset (x,y,sizeof (x))7 using namespacestd;8typedefLong LongLL;9 Const intinf=0x3f3f3f3f;Ten Const intmaxn=100010<<1; One structpoint{ A     Doublex, y; -Point (Doublex=0,Doubley=0): X (x), Y (y) {} - }; the typedef point Vector; - Point DT[MAXN]; -Vectoroperator-(point A,point b) {returnVector (a.x-b.x,a.y-b.y);} - DoubleCross (Vector A,vector b) {returna.x*b.y-a.y*b.x;} + intMain () { -     intn,k,j; +      while(SCANF ("%d",&N), N) { Ak=0; at          for(intI=1; i<=n;i++) -scanf"%LF%LF%LF%LF", &dt[i].x,&dt[i].y,&dt[i+n].x,&dt[i+n].y); -printf"Top Sticks:"); -          for(intI=1; i<n;i++){ -              for(j=i+1; j<=n;j++){ -                 if(Cross (Dt[i]-dt[j],dt[i]-dt[j+n]) *cross (Dt[i+n]-dt[j],dt[i+n]-dt[j+n]) <=0) in                     if(Cross (Dt[j]-dt[i],dt[j]-dt[i+n]) *cross (Dt[j+n]-dt[i],dt[j+n]-dt[i+n]) <=0) -                          Break; to             } +             if(j==n+1) printf ("%d,", i); -         } theprintf"%d.\n", N);  *     } $     return 0;Panax Notoginseng}

Pick-up sticks (judging the intersection of two lines)

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.