# HDU 1147 pick-up sticks judgment line intersection ~ ~ Pay attention to judgment order!! Otherwise it's easy to timeout

Source: Internet
Author: User

Pick-up SticksTime limit:4000/2000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2216 Accepted Submission (s): 815

Problem Descriptionstan 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.

Inputinput consists of a number of cases. The data for each case is start with 1≤n≤100000, and the number of 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.

Outputfor 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.`
Code:
`#include <stdio.h> #define MAX 100100struct point{double x, y; Point operator-[point P] {point ans; ans.x = x-p.x; ans.y = y-p.y; return ans;}}; struct Segment{point s, e; bool cover;} Seg[max];d ouble min (double x, double y) {return x>y?y:x;} Double Max (double x, double y) {return x>y?x:y;} BOOL Quickexclude (const Segment &a, const Segment &b) {Double minrx = min (a.s.x,a.e.x), minry = min (a.s.y,a.e.y) ;d ouble MAXRX = max (a.s.x,a.e.x), Maxry = max (a.s.y,a.e.y);d ouble mintx = min (b.s.x,b.e.x), MinTY = min (b.s.y,b.e.y);d ouble MAXTX = max (b.s.x,b.e.x), maxty = max (B.S.Y,B.E.Y), if (Max (MINTX,MINRX) >min (MAXTX,MAXRX) && Max (MinTY, Minry) >min (Maxty,maxry)) {return false;} return true;} Double F (Point P1, point p2) {return p1.x*p2.y-p1.y*p2.x;} BOOL Ifintersect (Segment &a, Segment &b) {if (Quickexclude (b)) {if (f (A.S-B.S,B.E-B.S) *f (B.E-B.S,A.E-B.S) >=0 &&f (B.S-A.S,A.E-A.S) *f (A.E-A.S,B.E-A.S) >=0) {return true;}} return false;} int main () {INT N; ~scanf ("%d", &n) && N) {for (int i = 0; i < n; ++i) {scanf ("%lf%lf%lf%lf", &seg[i].s.x,&se G[I].S.Y,&AMP;SEG[I].E.X,&AMP;SEG[I].E.Y); seg[i].cover = false;} for (int i = 0; i < n; ++i)//attention can only be written like this!! The following code example has a timeout {for (int j = i+1; j < n; ++j) {if (Ifintersect (Seg[i],seg[j])) {seg[i].cover = true; break;}}}  /* Time-OUT code!!! for (int i = 0, i < n; ++i) {for (int j = i+1; j < n; ++j) {if (!seg[i].cover) {if (Ifintersect (Seg[i],seg[j])) {Seg[i]. Cover = true; break;}}} */int i = 0;for (i = 0; i < n; ++i) {if (!seg[i].cover) {printf ("Top Sticks:%d", i+1); break;}} for (i=i+1; i < n; ++i) {if (!seg[i].cover) {printf (",%d", i+1);}} Puts (".");} return 0;}`

with June

HDU 1147 pick-up sticks judgment line intersection ~ ~ Pay attention to judgment order!! Otherwise it's easy to timeout

Related Keywords:

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.