显然,画图可知,最后看见的线段一定组成了一个下凸壳。
而且从左向右的线段的斜率一定是递增的。
所以我们对斜率排序,(由大到小和由小到大都无所谓),然后通过初中数学知识计算一下交点,用单调栈维护可以看见的部分即可。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
struct node
{
int a,b;
int id;
bool operator<(const node &rhs)const
{
if(a==rhs.a) return b>rhs.b;
return a>rhs.a;
}
}e[maxn];
int ans[maxn],st[maxn],top = 0;
double cp(int x,int y)
{
return double(e[x].b-e[y].b)/double(e[y].a-e[x].a);
}
int main()
{
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&e[i].a,&e[i].b);
e[i].id = i;
}
sort(e+1,e+1+n);
for(int i=1;i<=n;i++)
{
if(e[i].a==e[i-1].a && i!=1) continue;
while(top>1 && cp(st[top],i)>=cp(st[top],st[top-1])) top--;
st[++top] = i;
ans[top] = e[i].id;
}
sort(ans+1,ans+top+1);
for(int i=1;i<=top;i++) printf("%d ",ans[i]);
return 0;
}