先吹一波司机强
1007: [HNOI2008]水平可见直线
Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 6177 Solved: 2342
[ 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
-1 0
1 0
0 0
Sample Output
1 2
HINT
Source
司机好强啊司机稳啊
司机Au啊
斜率排序,用栈维护
如果这条直线和栈顶的交点在上一个交点左边 就Pop
正确性显然
%%%
#include<bits/stdc++.h>
using namespace std;
const int maxn=50050;
const double eps=1e-8;
struct line
{
double k,b;
int id;
bool operator < (const line & a) const
{
if(fabs(k-a.k)<eps) return b<a.b;
return k<a.k;
}
}e[maxn],st[maxn];
double cross(line a,line b)
{
return (a.b-b.b)/(b.k-a.k);
}
int n;
int top;
inline void insert(line x)
{
while(top)
{
if(fabs(st[top].k-x.k)<eps) top--;
else if(top>1&&cross(x,st[top-1])<=cross(st[top],st[top-1])) top--;
else break;
}
st[++top]=x;
}
bool ans[maxn];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&e[i].k,&e[i].b);
e[i].id=i;
}
sort(e+1,e+n+1);
for(int i=1;i<=n;i++)
insert(e[i]);
for(int i=1;i<=top;i++)
ans[st[i].id]=true;
for(int i=1;i<=n;i++)
if(ans[i])
printf("%d ",i);
}