poj2954

用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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值