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 2horizontal visible line must constitute a convex half convex bag, drawing can be found, the lower convex packet intersection of the horizontal axis monotonically increment, so that you can use a stack to maintainand then there's No.
1#include <cstdio>2#include <algorithm>3#include <iostream>4#include <cmath>5 #defineEPS 1e-86 Const intinf=10000000;7 using namespacestd;8 structnode{Doubleb;intNo;} l[100010];9 intn,top,stack[100100];Ten Doublex; One BOOLCMP (node A,node b) { A if(Fabs (A.A-B.A) <eps)returna.b<b.b; - Else returna.a<B.A; - } the - Doublecal (node A,node b) { - return(a.b-b.b)/(b.a-a.a); - } + - BOOLCMP2 (intAintb) { + returnl[a].no<l[b].no; A } at - intMain () { -scanf"%d",&n); - for(intI=1; i<=n;i++) -scanf"%LF%LF", &l[i].a,&l[i].b), l[i].no=i; -Sort (L +1, l+n+1, CMP); in DoubleNow= (l[1].b-l[2].B)/(l[2].a-l[1].a); - for(intI=1; i<=n;i++){ to while(top) { + if(Fabs (L[I].A-L[STACK[TOP]].A) <eps) top--; - Else if(top>1&&cal (l[i],l[stack[top-1]]) <=cal (l[stack[top-1]],l[stack[top])) thetop--; * Else Break; $ }Panax Notoginsengstack[++top]=i; - } theSort (stack+1, stack+1+top,cmp2); +printf"%d", l[stack[1]].no); A for(intI=2; i<=top;i++) printf ("%d", l[stack[i]].no); the}
"Bzoj 1007" [HNOI2008] Horizontal visible Line