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 straight lines: 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 2HINTSourceSolution
Sort by slope from small to large to maintain a lower convex hull
To remove the intersection of the newly added line and the convex hull in the right line, because the new line must be in the convex hull of the line that precedes it.
1#include <bits/stdc++.h>2 using namespacestd;3 Const DoubleEPS = 1e-8;4 struct Line5 {6 intID;7 DoubleK, B;8 BOOL operator< (ConstLine &RHS)Const9 {Ten returnFabs (K-RHS.K) < EPS? b < Rhs.b:k <RHS.K; One } A}a[100005]; - intsta[100005], ans[100005]; - the DoubleGetxintx) - { - return(A[sta[x]].b-a[sta[x-1]].B)/(A[sta[x-1]].K-a[sta[x]].k); - } + - intMain () + { A intn, top; atCIN >>N; - for(inti =1; I <= N; ++i) - { -CIN >> A[I].K >>a[i].b; -A[i].id =i; - } inSort (A +1, A + n +1); -Sta[top =1] =1; to for(inti =2; I <= N; ++i) + { -Sta[++top] =i; the while(Top >1) * if(Fabs (A[i].k-a[sta[top-1]].K) < EPS) Sta[--top] =i; $ Else if(Top >2&& getx (top)-Getx (Top-1) <EPS)Panax NotoginsengSta[--top] =i; - Else Break; the } + for(inti =1; I <= top; ++i) AAns[i] =a[sta[i]].id; theSort (ans +1, ans + top +1); + for(inti =1; I <= top; ++i) -cout << Ans[i] <<' '; $cout <<Endl; $ return 0; -}
View Code
[BZOJ1007] [HNOI2008] Horizontal visible straight line (convex bag)