P3194 [HNOI2008]水平可见直线

传送门

我们把所有的直线按斜率从小到大排序,然后用单调栈维护
发现,如果当前直线与\(st[top-1]\)直线的交点的横坐标大于等于与\(st[top]\)的交点的横坐标,当前直线可以覆盖掉\(st[top]\)
这个可以画图理解一下

//minamoto
#include<bits/stdc++.h>
#define rint register int
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
int read(){
    int res,f=1;char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=50005;
struct node{
    int a,b,id;
    inline bool operator <(const node &q)const{return a==q.a?b>q.b:a<q.a;}
}p[N];int n,st[N],top;
inline double solve(int i,int j){return (double)(p[i].b-p[j].b)/(p[j].a-p[i].a);}
int main(){
//  freopen("testdata.in","r",stdin);
    n=read();for(rint i=1;i<=n;++i)p[i].a=read(),p[i].b=read(),p[i].id=i;
    sort(p+1,p+1+n),st[top=0]=1;
    for(rint i=2;i<=n;++i){
        if(p[i].a==p[i-1].a)continue;
        while(top&&solve(st[top],i)<=solve(st[top-1],i))--top;
        st[++top]=i;
    }for(rint i=0;i<=top;++i)st[i]=p[st[i]].id;
    sort(st,st+1+top);for(rint i=0;i<=top;++i)printf("%d ",st[i]);return 0;
}

转载于:https://www.cnblogs.com/bztMinamoto/p/9989533.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值