poj2954

来源:互联网 发布:鹏业软件网址 编辑:程序博客网 时间:2024/05/22 14:41

用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;}

0 0
原创粉丝点击