1007: [HNOI2008]水平可见直线

时间:2023-03-09 15:21:20
1007: [HNOI2008]水平可见直线

先对a排序,a相等的话就对b排序;

维护一个栈,每次取栈的头两个,和当前的直线相比较;

如果当前的直线把头第一个屏蔽,就将他出栈,一直到不能屏蔽为止;

代码:

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 500005
using namespace std; int st[maxn],top;
int num[maxn]; struct line
{
int a,b;
int id;
bool operator<(const line &t)const
{
if(a==t.a)return b>t.b;
else return a<t.a;
}
} l[maxn]; bool check(int x,int y,int z)
{
double x1=((double)(l[y].b-l[x].b))/((double)(l[x].a-l[y].a));
double x2=((double)(l[z].b-l[x].b))/((double)(l[x].a-l[z].a));
if(x1<x2||(x1-x2)<0.00001)return ;
return ;
} int main()
{
int n;
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d%d",&l[i].a,&l[i].b);
l[i].id=i;
}
sort(l+,l+n+);
for(int i=; i<=n; i++)
{
while(top>)
{
if(check(i,st[top-],st[top-]))top--;
else break;
}
if(top==||l[st[top-]].a!=l[i].a)
st[top++]=i;
}
int cnt=;
for(int i=; i<top; i++)
num[cnt++]=l[st[i]].id;
sort(num,num+cnt);
for(int i=; i<cnt; i++)
printf("%d ",num[i]);
puts("");
return ;
}