bzoj 1007

来源:互联网 发布:thinkphp商城源码下载 编辑:程序博客网 时间:2024/05/16 09:22

这是一个大水题


只需要维护一下凸包就好啦
画一下图发现斜率相同在下面的就看不见啦
斜率不同的手画一下直线交点就好啦
简简单单的栈

#include<bits/stdc++.h>using namespace std;const int MX = 500000 ;const double eps = 1e-8 ;struct node{    double k,b;    int id;}e[MX];int n,top,sta[MX],ans[MX];bool com(node a,node b){    return (fabs(a.k-b.k)<eps)?a.b<b.b:a.k<b.k;}double getx(int x){    node a=e[sta[x]],b=e[sta[x-1]];    return (a.b-b.b)/(b.k-a.k);}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,com);    sta[++top]=1;    for(int i=2;i<=n;i++)    {       sta[++top]=i;       while(fabs(e[i].k-e[sta[top-1]].k)<eps) sta[--top]=i;       while(top>2&&(getx(top)-getx(top-1))<eps) sta[--top]=i;    }    for(int i=1;i<=top;i++)      ans[i]=e[sta[i]].id;    sort(ans+1,ans+top+1);    for(int i=1;i<=top;i++) printf("%d ",ans[i]);}

心得:
1.凸包是非常重要的,还可以用在斜率优化
2.用纸和笔画一下图比较好

原创粉丝点击