1007: [HNOI2008] Horizontal visible line time limit:1 Sec Memory limit:162 MB
submit:5120 solved:1899
[Submit] [Status] [Discuss] Description
There are n linear l1,l2 on the Xoy Cartesian plane,... Ln, if the Y value is positive infinity down, you can see a sub-segment of Li, it is said that Li is visible, otherwise li is covered.
For example, for a line:
L1:y=x; L2:y=-x; L3:y=0
Then L1 and L2 are visible, and L3 are covered.
gives a line of N, expressed as a form of y=ax+b (| a|,| b|<=500000), and the N line 22 does not coincide. Find all the visible lines.
Input
The first behavior n (0 < n < 50000), the next n-line input Ai,bi
Output
From small to large output visible line number, 22 is separated by a space, the last number must also have a space behind
Sample Input3
-1 0
1 0
0 0Sample Output1 2Hintsource
Ideas
monotonic stack maintenance under convex hull.
Code
1#include <cmath>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #definefor (A,B,C) for (int a= (b); a<= (c); a++)6 using namespacestd;7 8 Const intN =50000+Ten;9 Const DoubleEPS = 1e-8;Ten One structLine { A Doubleb;intR; - BOOL operator< (Constline& RHS)Const { - if(Fabs (A-RHS.A) <eps)returnb<rhs.b; the Else returna<RHS.A; - } - }l[n],s[n]; - + DoubleCross (line X1,line x2) { - return(x2.b-x1.b)/(x1.a-x2.a); + } A at intN,flag[n],top; - - intMain () { -scanf"%d",&n); -for (I,1, N) { -scanf"%LF%LF",&l[i].a,&l[i].b); inL[i].r=i; - } toSort (L +1, l+n+1); +for (I,1, N) { - while(top) { the if(Fabs (S[TOP].A-L[I].A) <eps) top--; * Else if(top>1&& Cross (l[i],s[top-1]) <=cross (s[top],s[top-1])) top--; $ Else Break;Panax Notoginseng } -s[++top]=L[i]; the } +for (I,1, top) flag[s[i].r]=1; Afor (I,1, N)if(Flag[i]) theprintf"%d", i); + return 0; -}
Bzoj 1007 [HNOI2008] Horizontal visible line (monotonic stack)