[HNOI2008]水平可见直线

水平可见直线,半平面交??什么鬼,被dalao低飞。我只是用一个小小的数单调队列做出来的。具体就是通过维护一个上升的斜率单调队列然后不停单调就做出来了。神奇的单调队列,说实话我忘了怎么打模版了。
#include<map>
#include<queue>
#include<cmath>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define qread(x) x=read()
#define mes(x,y) memset(x,y,sizeof(x))
#define mpy(x,y) memcpy(x,y,sizeof(x))
#define Maxn 50000
#define INF 2147483647
#define eps 1e-6
inline int read(){
    char ch=getchar();
    int f=1,x=0;
    while(!(ch>='0'&&ch<='9')){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}
struct Pfun{
    int x;double k,b;
}P[Maxn+1];
int cmp(const Pfun a,const Pfun b){
    return (a.k<b.k||(a.k==b.k&&a.b<b.b));
}
int n,top,sta[Maxn+1],ans[Maxn+1];
double Pnode(int x,int y){
    return (P[y].b-P[x].b)/(P[x].k-P[y].k);
}
int main(){
    qread(n);
    for(int i=1;i<=n;i++){
        qread(P[i].k);qread(P[i].b);
        P[i].x=i;
    }
    std::sort(P+1,P+n+1,cmp);
	top=0;
    for(int i=1;i<=n;i++){
        while(top>0&&P[i].k-P[sta[top]].k<eps)top--;
        while(top>1&&Pnode(sta[top-1],sta[top])>=Pnode(sta[top],i))top--;
        sta[++top]=i;
    }
    for(int i=1;i<=top;i++)ans[i]=P[sta[i]].x;
    std::sort(ans+1,ans+top+1);
    for(int i=1;i<=top;i++)printf("%d ",ans[i]);printf("\n");
    return 0;
}
 

查看原文:http://hz2016.tk/blog/?p=63
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值