• [HNOI2008]水平可见直线


    直线代入一点值相当于向量 (k,a) 和 (x, 1) 的点积,于是根据点积最大化思想直接跑上凸壳就对了。

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
     
    const int MAXN = 50010;
    typedef long long LL;
    struct Point {
        int x, y, idx;
        explicit Point(int a = 0, int b = 0) { x = a, y = b; }
        inline bool operator < (const Point & b) const {
            return x == b.x ? y > b.y : x < b.x;
        }
        inline Point operator - (const Point & b) const {
            return Point(x - b.x, y - b.y);
        }
    } ps[MAXN];
    LL cross(const Point & a, const Point & b) {
        return static_cast<LL> (a.x) * b.y - static_cast<LL> (a.y) * b.x;
    }
    int n, hav[MAXN];
    int st[MAXN], top;
    void solve() {
        std::sort(ps + 1, ps + 1 + n);
        st[1] = 1; st[top = 2] = 2;
        for (int i = 3; i <= n; ++i) {
            while (top >= 2 && cross(ps[st[top]] - ps[st[top - 1]], ps[i] - ps[st[top]]) >= 0) --top;
            st[++top] = i;
        }
        for (int i = 1; i <= top; ++i) hav[ps[st[i]].idx] = true;
    }
    int main() {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) 
            scanf("%d%d", &ps[i].x, &ps[i].y), ps[i].idx = i;
        solve();
        for (int i = 1; i <= n; ++i) if (hav[i]) printf("%d ", i);
        putchar(10);
        return 0;
    }
    
  • 相关阅读:
    信息系统项目管理师沟通的四个好习惯
    Android 线程
    替换exe程序图标DLL
    Python 邮件类
    android自适应屏幕方向和大小
    sqlserver 存储过程
    FinalData 数据恢复工具[绿色版]
    Python Python 正则 取中括号值
    在Button任意位置加图片效果
    android GPRS
  • 原文地址:https://www.cnblogs.com/daklqw/p/10361514.html
Copyright © 2020-2023  润新知