1. 程式人生 > >1007: [HNOI2008]水平可見直線

1007: [HNOI2008]水平可見直線

stream 出了 struct put cst solved ostream top mem

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 }

1007: [HNOI2008]水平可見直線