zoukankan      html  css  js  c++  java
  • 【POJ】2954 Triangle(pick定理)

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

    表示我交了20+次...

    为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QAQ我居然查了如此久都没查出来!!!!注意负数啊负数啊啊啊啊啊啊啊

    本题是pick定理:当多边形的顶点均为整数时,面积=内部整点+边上整点/2-1

    然后本题要求内部整点

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <set>
    #include <map>
    using namespace std;
    typedef long long ll;
    #define pii pair<int, int>
    #define mkpii make_pair<int, int>
    #define pdi pair<double, int>
    #define mkpdi make_pair<double, int>
    #define pli pair<ll, int>
    #define mkpli make_pair<ll, int>
    #define rep(i, n) for(int i=0; i<(n); ++i)
    #define for1(i,a,n) for(int i=(a);i<=(n);++i)
    #define for2(i,a,n) for(int i=(a);i<(n);++i)
    #define for3(i,a,n) for(int i=(a);i>=(n);--i)
    #define for4(i,a,n) for(int i=(a);i>(n);--i)
    #define CC(i,a) memset(i,a,sizeof(i))
    #define read(a) a=getint()
    #define print(a) printf("%d", a)
    #define dbg(x) cout << (#x) << " = " << (x) << endl
    #define error(x) (!(x)?puts("error"):0)
    #define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }
    #define printarr1(a, b) for1(_, 1, b) cout << a[_] << '	'; cout << endl
    inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
    inline const int max(const int &a, const int &b) { return a>b?a:b; }
    inline const int min(const int &a, const int &b) { return a<b?a:b; }
    
    struct Point { int x, y; }a[4];
    int area(Point &a, Point &b, Point &c) {
    	static int x1, x2, y1, y2;
    	x1=a.x-c.x; y1=a.y-c.y;
    	x2=b.x-c.x; y2=b.y-c.y;
    	return abs(x1*y2-x2*y1);
    }
    int gcd(int a, int b) { return b?gcd(b, a%b):a; }
    int onLine(Point &a, Point &b) {
    	static int x, y;
    	x=abs(a.x-b.x);
    	y=abs(a.y-b.y);
    	return gcd(x, y);
    }
    int main() {
    	while(1) {
    		int sum=0;
    		rep(i, 3) read(a[i].x), read(a[i].y), sum|=a[i].x|a[i].y;
    		if(!sum) return 0;
    		int on=onLine(a[0], a[1])+onLine(a[1], a[2])+onLine(a[2], a[0]);
    		printf("%d
    ", (area(a[0], a[1], a[2])-on)/2+1);
    	}
    	return 0;
    }
    

      


    Description

    A lattice point is an ordered pair (x, y) 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 x1, y1, x2, y2, x3, and y3, where (x1, y1), (x2, y2), and (x3, y3) are the coordinates of vertices of the triangle. All triangles in the input will be non-degenerate (will have positive area), and −15000 ≤ x1, y1, x2, y2, x3, y3 ≤ 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

  • 相关阅读:
    .NET Core前后端分离快速开发框架(Core.3.0+AntdVue)
    关于框架
    什么是 https ?这应该是全网把 https 讲的最好的一篇文章了
    NET手撸绘制TypeScript类图——下篇
    及时发现问题,力争找到更好的解决办法,而不是得过且过
    一个命令永久禁用Win10驱动程序强制签名
    表达式的结果为true或false
    Parcel 搭建浏览器自动刷新的 非 SPA项目
    Gulp 搭建前端非SPA 项目, 修改文件浏览器自动刷新
    vue 里 this.$parent 作用
  • 原文地址:https://www.cnblogs.com/iwtwiioi/p/4193364.html
Copyright © 2011-2022 走看看