1007: [HNOI2008]水平可见直线

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 8846  Solved: 3418
[Submit][Status][Discuss]

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
 
70分,不知道出了什么玄学问题。。。明天填坑
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 using namespace std;
 6 
 7 const int MAXN=50000+5;
 8 struct Line
 9 {
10     int a,b,id;
11 }L[MAXN];
12 int st[MAXN],ans[MAXN];
13 int n,top;
14 
15 bool cmp(Line A,Line B)
16 {
17     if(A.a!=B.a)
18         return A.a<B.a;
19     else A.b>B.b;
20 }
21 
22 double getx(int A,int B)
23 {
24     return (double)(L[B].b-L[A].b)/(double)(L[A].a-L[B].a);
25 }
26 
27 int main()
28 {
29     scanf("%d",&n);
30     for(int i=1;i<=n;i++)
31     {
32         scanf("%d %d",&L[i].a,&L[i].b);
33         L[i].id=i;
34     }
35     sort(L+1,L+n+1,cmp);
36     for(int i=1;i<=n;i++)
37     {
38         if(i!=1&&L[i-1].a==L[i].a) continue;
39         while(top>1&&getx(st[top],i)<=getx(st[top-1],st[top])) top--;
40         st[++top]=i;
41         ans[top]=L[i].id;
42     }
43     sort(ans+1,ans+top+1);
44     for(int i=1;i<=top;i++) printf("%d ",ans[i]);
45     return 0;
46 }

猜你喜欢

转载自www.cnblogs.com/InWILL/p/9275789.html