zoukankan      html  css  js  c++  java
  • HDU

    昨天吉老师讲了皮克定理

    皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:

    如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .

    皮克定理用于计算点阵中顶点在格点上的多边形面积。对于一个顶点全部在格点上的多边形来说,它的面积计算有如下特点:

    如果用a表示位于多边形内部的格点数,b表示位于多边形边界上的格点数,则多边形面积可表示为S = a + b/2 – 1 .

    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).

    InputThe 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. 

    OutputFor 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

    所以直接叉积算面积,点的话可以gcd,so easy

    #include<bits/stdc++.h>
    using namespace std;
    #define x first
    #define y second
    pair<int,int>P[3],M[3];
    int main()
    {
        while(cin>>P[0].x>>P[0].y>>P[1].x>>P[1].y>>P[2].x>>P[2].y)
        {
            if(!P[0].x&&!P[0].y&&!P[1].x&&!P[1].y&&!P[2].x&&!P[2].y)break;
            int sum=abs((P[1].x-P[0].x)*(P[2].y-P[0].y)-(P[1].y-P[0].y)*(P[2].x-P[0].x));
            for(int i=0;i<3;i++)
            M[i].x=abs(P[i].x-P[i-1<0?i+2:i-1].x),M[i].y=abs(P[i].y-P[i-1<0?i+2:i-1].y),sum-=__gcd(M[i].x,M[i].y);
            cout<<sum/2+1<<"
    ";
        }
    }

     友情放送多边形重心(也可以求面积,取abs就好了),这篇博客的C

  • 相关阅读:
    Feature的开发和部署
    MOSS 2007应用如何修改上传文件大小及类型的限制
    学习Ajax的优秀网站
    Office SharePoint 权限开发
    Asp.net操作Excel汇总
    如何取到MOSS列表中item的链接
    解决MOSS、SharePoint的未知错误
    Ajax 之 XMLHttpRequest
    C#中从资源文件里加载文件
    linux 技巧:使用 screen 管理你的远程会话 [linux]
  • 原文地址:https://www.cnblogs.com/BobHuang/p/9510331.html
Copyright © 2011-2022 走看看