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;
}
之前用的模板都是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;
}
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学算法 - 求凸包的Garham's Scan算法的C++实现
- 初学ACM - 组合数学基础题目PKU 1833