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

  • 相关阅读:
    左侧列固定的表格
    百度地图上添加多个标记,标记上添加信息展示窗口、跳转到导航界面
    vue-cli4版本解决eslint问题
    使用脚手架搭建项目
    正则表达式学习
    函数参数:
    装饰器(重点)
    列表生成式、生成器、迭代器
    logging 日志模块
    json 、 pickle 、shelve序列化
  • 原文地址:https://www.cnblogs.com/BobHuang/p/9510331.html
Copyright © 2011-2022 走看看