首页 > 其他 > 详细

Codeforces 1142C U2 凸包 (看题解)

时间:2019-11-05 12:00:13      阅读:89      评论:0      收藏:0      [点我收藏+]

U2

把坐标转(x, y)换成(x, y - x * x)之后就是求个上凸包

#include<bits/stdc++.h>
#define LL long long
using namespace std;

const int N = (int)1e5 + 7;

struct Point {
    LL x, y;
    Point(LL x = 0, LL y = 0) : x(x), y(y) {}
    bool operator < (const Point &rhs) const {
        return x < rhs.x || (x == rhs.x && y > rhs.y);
    }
    Point operator - (const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }
    void read() {
        scanf("%lld%lld", &x, &y);
        y = y - x * x;
    }
};

LL det(Point A, Point B) {
    return A.x * B.y - A.y * B.x;
}

int n, m;
Point a[N];
Point b[N];

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) a[i].read();
    sort(a, a + n);
    for(int i = 0; i < n; i++) {
        if(m == 0 || a[i].x != a[i - 1].x) a[m++] = a[i];
    }
    n = m;
    m = 0;
    for(int i = 0; i < n; i++) {
        while(m >= 2 && det(b[m - 1] - b[m - 2], a[i] - b[m - 1]) >= 0) m--;
        b[m++] = a[i];
    }
    printf("%d\n", m - 1);
    return 0;
}

/**
**/

 

Codeforces 1142C U2 凸包 (看题解)

原文:https://www.cnblogs.com/CJLHY/p/11797390.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!