[HNOI2008]水平可见直线

Description

  在xoy直角坐标平面上有n条直线L1,L2,...Ln,若在y值为正无穷大处往下看,能见到Li的某个子线段,则称Li为
可见的,否则Li为被覆盖的.
例如,对于直线:
L1:y=x; L2:y=-x; L3:y=0
则L1和L2是可见的,L3是被覆盖的.
给出n条直线,表示成y=Ax+B的形式(|A|,|B|<=500000),且n条直线两两不重合.求出所有可见的直线.

Input

  第一行为N(0 < N < 50000),接下来的N行输入Ai,Bi

Output

  从小到大输出可见直线的编号,两两中间用空格隔开,最后一个数字后面也必须有个空格

Sample Input

3
-1 0
1 0
0 0

Sample Output

1 2
 

代码

#include<cstdio>
#include<cmath>
#include<algorithm>
#define E 1e-8
using namespace std;
struct data{double a,b;int n;}l[50001];
data st[50001];bool ans[50001];
int top,n;
inline bool cmp(data a,data b){return fabs(a.a-b.a)<E?a.b<b.b:a.a<b.a;}
double crossx(data x1,data x2){return (x2.b-x1.b)/(x1.a-x2.a);}
void insert(data a){while(top){if(fabs(st[top].a-a.a)<E)top--;
    else if(top>1&&crossx(a,st[top-1])<=crossx(st[top],st[top-1]))top--;
    else break;}st[++top]=a;}
void work(){for(int i=1;i<=n;i++)insert(l[i]);
    for(int i=1;i<=top;i++)ans[st[i].n]=1;
    for(int i=1;i<=n;i++)if(ans[i])printf("%d ",i);}
int main(){scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%lf%lf",&l[i].a,&l[i].b),l[i].n=i;
    sort(l+1,l+n+1,cmp);work();return 0;}
原文地址:https://www.cnblogs.com/muzu/p/8052616.html