poj 2954 Triangle(Pick公式+GCD关系+面积公式)

Triangle
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4069 Accepted: 1787

Description

lattice point is an ordered pair (xy) where x and y are both integers. Given the coordinates of the vertices of a triangle (which happen to be lattice points), you are to count the number of lattice points which lie completely inside of the triangle (points on the edges or vertices of the triangle do not count).

Input

The input test file will contain multiple test cases. Each input test case consists of six integers x1y1x2y2x3, and y3, where (x1y1), (x2y2), and (x3y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1y1x2y2x3y3 ≤ 15000. The end-of-file is marked by a test case with x1 =  y1 = x2 = y2 = x3 = y3 = 0 and should not be processed.

Output

For each input case, the program should print the number of internal lattice points on a single line.

Sample Input

0 0 1 0 0 1
0 0 5 0 0 5
0 0 0 0 0 0

Sample Output

0
6

Source

题目:http://poj.org/problem?id=2954

题意:给你个三角形,要求在三角形内的整数点的个数

分析:poj 1265的简化版吧,套用公式就过了

代码:

#include<cstdio>
#include<iostream>
using namespace std;
int gcd(int a,int b)
{
    if(a<0)a=-a;
    if(b<0)b=-b;
    int c;
    while(b)
    {
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
int main()
{
    int x1,y1,x2,y2,x3,y3,area,line;
    while(~scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3),x1|y1|x2|y2|x3|y3)
    {
        area=((x2-x1)*(y3-y1)-(y2-y1)*(x3-x1))/2;
        if(area<0)area=-area;
        line=gcd(x1-x2,y1-y2)+gcd(x1-x3,y1-y3)+gcd(x2-x3,y2-y3);
        printf("%d\n",area+1-line/2);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值