[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
-1 0
1 0
0 0
Sample Output
#include<cstdio>
#include<stack>
#include<algorithm>
#define eps 1e-8
#define Maxn 50001
using namespace std;
typedef double D;
class Node{
public:
int num;
D k,b;
};
stack<Node>Q;
Node t[Maxn],h[Maxn];
bool cmp(const Node A,const Node B){
return (A.k<B.k)||((A.k-B.k<eps)&&(A.b>B.b)); //problem 1
}
bool cmp2(const Node A,const Node B){
return A.num<B.num;
}
double public_node(Node A,Node B){
return (B.b-A.b)/(A.k-B.k);
}
bool Istrue(int i){
Node tmp=Q.top(),tmp2;
Q.pop();
if(!Q.empty())
tmp2=Q.top();
else
tmp2=tmp;
Q.push(tmp);
if(public_node(h[i],tmp2)<=public_node(tmp,tmp2))
return true;
return false;
}
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;++i)
scanf("%lf%lf",&h[i].k,&h[i].b),
h[i].num=i;
sort(h,h+n,cmp);
Q.push(h[0]);
for(int i=1;i<n;++i){
if((h[i].k-h[i-1].k)<eps) // problem 2
continue;
while(Q.size()>1&&!Q.empty()&&Istrue(i))
Q.pop();
Q.push(h[i]);
}
int i=0;
while(!Q.empty()){
t[i++]=Q.top();
Q.pop();
}
sort(t,t+i,cmp2);
for(int j=0;j<i;++j)
printf("%d ",t[j].num+1);
}