L3-009 长城

#include<bits/stdc++.h>
using namespace std;
struct point{
    int x, y, id;
    point(int a = 0, int b = 0){x = a, y = b; }
    friend point operator -(point a, point b){
        return point(a.x - b.x, a.y - b.y);
    }
    friend double operator * (point a,point b){
        return a.x*b.y-b.x*a.y;
    }

}points[100005];
int across(point a, point b, point c){
    return (c-a) * (b - a);
}
int main()
{
    int n, x, y, cnt = 0;
    cin >> n;
    int s[100005] = {0}, p[100005] = {0};
    for(int i = 1; i <= n; i++){
        cin >> points[i].x >> points[i].y;
        points[i].id = i;
        while(cnt > 1){
            if(across(points[i], points[p[cnt-1]], points[p[cnt-2]])){
                    cnt--;
            }
            else break;
        }
        if(cnt){
            p[points[cnt-1].id] = 1;
        }
        p[cnt++] = i;
    }
    int sum = 0;
    for(int i = 0; i <= n; i++){
        if(p[i]) sum++;
    }
    cout << sum;
}

  

原文地址:https://www.cnblogs.com/jrjxt/p/13622327.html