团体程序设计天梯赛-练习集 L3-009 长城(凸包)

题目链接

由于每个点只能看到该点左边的点,那么不仅仅是普通的凸包问题,在求凸包的过程中还需要求出每个凸起来的点才是答案。

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

typedef long long ll;
#define int ll
#define INF 0x3f3f3f3f
#define MAXM 100000 + 10
#define MAXN 100000 + 10
const ll mod = 998244353;
#define fir first
#define sec second

int n;
struct node {
    int x, y;
}no[MAXN];
int num;
int vis[MAXN], id[MAXN];

int cro_mul(node now, node mid, node pre)
{
    int x1 = mid.x - pre.x, y1 = mid.y - pre.y;
    int x2 = now.x - mid.x, y2 = now.y - mid.y;
    return x1 * y2 - x2 * y1;
}

signed main()
{
    cin >> n;
    for(int i = 0; i < n; i ++) {
        int x, y; cin >> x >> y;
        node now; now.x = x, now.y = y;
        while(num >= 2 && cro_mul(now, no[num], no[num-1]) <= 0) {
            num --;
        }
        no[++num].x = x, no[num].y = y, id[num] = i;
        if(i >= 2) vis[id[num-1]] = 1;
    }

    int ans = 0;
    for(int i = 1; i < n; i ++) {
        ans += vis[i];
    }
    cout << ans << endl;
}

/*

The WAM is F**KING interesting .
9
8 3
7 0
6 2
5 1
4 1
3 3
2 2
1 0
0 1

3
8 3
7 0
6 2

3
3 0
2 0
1 0
*/

 

你可能感兴趣的:(团体程序设计天梯赛-练习集 L3-009 长城(凸包))