bzo1007 [HNOI2008]水平可见直线
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1007
所有可见直线形成下凸壳的样子。而且交点横坐标递增。
(特殊判断平行线。但是按b从小到大排过序后为什么不能正常地弄?)
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=50005; int n,stack[N],top,cnt; struct Node{ double k,b; int bh; }a[N],c[N]; bool ans[N]; double jd[N]; double cal(int u,int v){return (a[u].b-a[v].b)/(a[v].k-a[u].k);} bool cmp(Node u,Node v){return u.k==v.k?u.b<v.b:u.k<v.k;} int main() { scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lf%lf",&a[i].k,&a[i].b),a[i].bh=i; sort(a+1,a+n+1,cmp); if(n==1){printf("1 ");return 0;} for(int i=1;i<=n;i++) { while(a[i+1].k==a[i].k)i++; while(top>1&&cal(i,stack[top-1])<=jd[stack[top]])top--; if(top)jd[i]=cal(i,stack[top]);stack[++top]=i; } for(int i=1;i<=top;i++)ans[a[stack[i]].bh]=1; for(int i=1;i<=n;i++)if(ans[i])printf("%d ",i); return 0; }