欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Water Testing Gym - 101873G

程序员文章站 2022-03-29 22:28:04
...

https://cn.vjudge.net/problem/Gym-101873G

总结:

皮克原理: S=a+b/2−1,其中 S 是多边形面积,a 是多边形内部格点数目,b 是多边形边界上的格点数目。

对于两端点(x1,y1),(x2,y2) 都再格点上的一条线段,该线段上的格点数目为 gcd(|x1−x2|,|y1−y2|)+1;

叉乘是三角形面积两倍;

#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <tr1/unordered_map>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;

#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%I64d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define prl(i) printf("%I64d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define inf 1e18
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson (rt<<1)
#define rson (rt<<1|1)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

template<typename T>inline void read(T &x)
{
    x=0;
    static int p;p=1;
    static char c;c=getchar();
    while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
    while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
    x*=p;
}

//-----------------------------------------------

const int maxn=1e5+9;
const int mod=1e9+7;

struct point
{
    ll x,y;
}p[maxn];

ll chax(point a,point b)
{
    return a.x*b.y-a.y*b.x;
}

int main()
{
    //FAST_IO;
    //freopen("input.txt","r",stdin);

    int n;
    cin>>n;
    for(int i=1;i<=n;i++) cin>>p[i].x>>p[i].y;

    ll s=0;

    for(int i=1;i<n;i++) s+=chax(p[i],p[i+1]);
    s+=chax(p[n],p[1]);

    s=abs(s);

    ll b=0;
    for(int i=1;i<n;i++) b+=__gcd(abs(p[i].x-p[i+1].x),abs(p[i].y-p[i+1].y));
    b+=__gcd(abs(p[1].x-p[n].x),abs(p[1].y-p[n].y));

    cout<<(s-b+2)/2<<endl;
    return 0;
}