您的位置:首页 > 其它

poj2954

2016-07-28 18:41 344 查看
用nick定理

之前用的模板都是double 的= =,然后也是头一次将一堆模板删删删

tr_area这个是int 类型的,最后在处理两个/2过程同时进行,几个不同步的/2过程害得老夫debug了一小会= =#include <cstdio>
#include<iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

struct Point {
int x, y;
Point() {}
Point(int x, int y) {
this->x = x;
this->y = y;
}
void read() {
scanf("%d%d", &x, &y);
}
};

typedef Point Vector;

Vector operator - (Vector A, Vector B) {
return Vector(A.x - B.x, A.y - B.y);
}

bool operator < (const Point& a, const Point& b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}

const double eps = 1e-8;

//double Dot(Vector A, Vector B) {return A.x * B.x + A.y * B.y;} //点积
//double Length(Vector A) {return sqrt(Dot(A, A));} //向量的模
int Cross(Vector A, Vector B) {return A.x * B.y - A.y * B.x;} //叉积
int Area2(Point A, Point B, Point C) {return Cross(B - A, C - A);} //有向面积

int gcd(int a,int b){
if(b==0)return a;
return gcd(b,a%b);
}

Point p[3];
int tr_area;
int cnt;
int main()
{
while(scanf("%d%d%d%d%d%d",&p[0].x,&p[0].y,&p[1].x,&p[1].y,&p[2].x,&p[2].y)){
if(p[0].x==0&&p[0].y==0&&p[1].x==0&&p[1].y==0&&p[2].x==0&&p[2].y==0)break;
cnt=0;
tr_area=abs(Area2(p[0],p[1],p[2]));
for(int i=0;i<3;i++){
cnt+=gcd(abs(p[i].x-p[(i+1)%3].x),abs(p[i].y-p[(i+1)%3].y));
}
int ans;
//cout<<tr_area<<" "<<cnt<<endl;
ans=(tr_area-cnt+2)/2;
printf("%d\n",ans);
}
system("pause");
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ACM poj 计算几何