江鸟的困惑
来源:互联网 发布:智能机器人编程入门 编辑:程序博客网 时间:2024/04/30 21:47
Description
江鸟最近在做一项数学研究,平面上有一系列的整数点,他在平面上找了其中任意三个点,并且保证这三个点不在同一条直线上且没有重点,他的研究是什么呢?请看下文:他将这三个点用线段连成一个三角形,他现在想知道那些严格在三角形内部的整数点共有多少个。但他太SB了,他向你们这些编程高手求助,你能帮助他吗?为了简化问题,假设数据范围int就可以了。
Input
第一行输入一个正整数T,表示有多少测试数据。
以下T行,每一行输入六个整数x1,y1,x2,y2,x3,y3分别表示选取的三个点的坐标.
Output
对应于每组测试数据输出最后结果,格式参照Sample Output.
Sample Input
3
0 0 5 0 0 5
1 1 2 2 3 4
23 24 45 56 78 89
Sample Output
CASE 1: 6
CASE 2: 0
CASE 3: 146
#include<iostream>
#include<cmath>
using namespace std;
struct point
{
int x,y;
};
point t[3];
double area(point t[])
{
returnfabs((double)((t[0].x*t[1].y+t[1].x*t[2].y+t[2].x*t[0].y-t[1].x*t[0].y-t[2].x*t[1].y-t[0].x*t[2].y)/2));
}
int gcd(int x,int y)
{
if(y==0)return x;
else
return gcd(y,x%y);
}
int f(int a,int b)
{
if(a>=b) return a-b;
else return b-a;
}
int main()
{
inti,n,j;
cin>>n;
for(j=1;j<=n;j++)
{
int num1=0,num2=0,num3=0,s=0,n=0;
for(i=0;i<3;i++)
cin>>t[i].x>>t[i].y;
num1=gcd(f(t[0].x,t[1].x),f(t[0].y,t[1].y));
num2=gcd(f(t[0].x,t[2].x),f(t[0].y,t[2].y));
num3=gcd(f(t[1].x,t[2].x),f(t[1].y,t[2].y));
s=area(t);
cout<<"CASE"<<j<<":"<<"";
cout<<s-(num1+num2+num3)/2+1<<endl;
}
}
- 江鸟的困惑
- 江鸟的困惑
- 国产杀毒软件的困惑
- sso的困惑!
- 研究rds的困惑
- Classpath的困惑
- 产品设计策划的困惑!!!
- 工作的困惑
- JAVA的困惑!
- EJB的困惑
- Hibernate配置文件的困惑
- 人的困惑
- 我的困惑
- 学语言的困惑...
- 开始的困惑
- 困惑 的 回帖
- 读计算机专业的困惑
- IT人的困惑
- A Simple Math Problem
- Y/N
- above average
- Next K-Bit Number<T…
- Polynomial Integration<Cont…
- 江鸟的困惑
- 子字符串寻址
- Message Decowding
- Internet
- 杭电acm2004成绩转换
- Number Triangles
- 很简答的数学递归!
- Self Numbers
- 分解素因子(数论)