[HNOI2008]水平可见直线

按斜率排序后画个图,用单调栈维护这个半平面交

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int _(50010), INF(2147483647);

IL ll Read(){
    RG char c = getchar(); RG ll x = 0, z = 1;
    for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
    for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
    return x * z;
}

int n, a[_], b[_], id[_], s[_], top;

IL bool Cmp(RG int x, RG int y){  return a[x] != a[y] ? a[x] < a[y] : b[x] < b[y];  }

IL double Cross(RG int x, RG int y){  return 1.0 * (b[y] - b[x]) / (1.0 * (a[x] - a[y]));  }

int main(RG int argc, RG char* argv[]){
    n = Read();
    for(RG int i = 1; i <= n; ++i) a[i] = Read(), b[i] = Read(), id[i] = i;
    sort(id + 1, id + n + 1, Cmp);
    for(RG int i = 1; i <= n; ++i){
        while(top && a[id[i]] == a[s[top]]) --top;
        while(top > 1 && Cross(s[top - 1], s[top]) >= Cross(s[top - 1], id[i])) --top;
        s[++top] = id[i];
    }
    sort(s + 1, s + top + 1);
    for(RG int i = 1; i <= top; ++i) printf("%d ", s[i]);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值