BZOJ 1007 [HNOI2008] 水平可见直线

来源:互联网 发布:网络色情图片和小说 编辑:程序博客网 时间:2024/05/06 00:25

这题。。。精度问题+排序问题调了很久。只有一句mmp

#include <cstdio>#include <iostream>#include <cstdlib>#include <algorithm>#include <cmath>#include <cstring>using namespace std ;const double eps=1e-8;int n;typedef struct NODE{    double k,b;    int id;    bool operator <(const NODE & b)const{        if(this->k!=b.k) return this->k < b.k;        return this->b > b.b;    }}N;N a[50010],s[50010];bool ans[50010];int top;void init (){    cin >>n;    int i;    for (i=1;i<=n;i++){        scanf ("%lf %lf",&a[i].k,&a[i].b);        a[i].id=i;    }}double xcross (N a,N b){    return (b.b-a.b)/(a.k-b.k);}int main (){    init ();    int i;    sort (a+1,a+1+n);    memset (ans,false,sizeof(ans));    s[++top]=a[1];    for(i=2;i<=n;i++){        if(a[i].k-a[i-1].k<eps) continue;        while(top>1&&xcross(a[i],s[top])<=xcross(s[top],s[top-1]) ) top--;        s[++top]=a[i];    }    for (i=1;i<=top;i++){        ans[s[i].id]=true;    }    for (i=1;i<=n;i++){        if (ans[i]) printf ("%d ",i);    }    return 0;}
0 0
原创粉丝点击