bzoj 1007

这是一个大水题


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

#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.用纸和笔画一下图比较好

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值