Triangle POJ - 2954
题意:求一个三角形内包含多少个整数点
思路:求S,求on,in=(2S-on+2)/2;
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<string.h>
#include<iostream>
#include<algorithm>
#define PI acos(-1.0)
#define pb push_back
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=3e5+5;
const int MOD=1e9+7;
template <class T>
bool sf(T &ret){ //Faster Input
char c; int sgn; T bit=0.1;
if(c=getchar(),c==EOF) return 0;
while(c!='-'&&c!='.'&&(c<'0'||c>'9')) c=getchar();
sgn=(c=='-')?-1:1;
ret=(c=='-')?0:(c-'0');
while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0');
if(c==' '||c=='\n'){ ret*=sgn; return 1; }
while(c=getchar(),c>='0'&&c<='9') ret+=(c-'0')*bit,bit/=10;
ret*=sgn;
return 1;
}
struct Point{
int x,y;
Point(ll x=0, ll y=0) : x(x), y(y) {}
Point operator - (const Point &rhs) const{
return Point(x-rhs.x,y-rhs.y);
}
}p[4];
typedef Point Vector;
ll cross(Vector A,Vector B){
return A.x*B.y-A.y*B.x;
}
int main(void){
while(1){
int cnt=0;
for(int i=1;i<=3;i++){
sf(p[i].x),sf(p[i].y);
if(p[i].x==0) cnt++;
if(p[i].y==0) cnt++;
}
if(cnt==6) break;
ll ds=cross(p[1],p[2])+cross(p[2],p[3])+cross(p[3],p[1]);
// ll ds=cross(p[1]-p[2],p[1]-p[3]);
if(ds<0) ds=-ds;
// cout <<ds<<endl;
ll on=1ll*abs(__gcd(p[1].x-p[2].x,p[1].y-p[2].y))+abs(__gcd(p[3].x-p[2].x,p[3].y-p[2].y))+
abs(__gcd(p[3].x-p[1].x,p[3].y-p[1].y));
ll in=1ll*(ds+2-on)/2;
printf("%lld\n",in);
}
return 0;
}