zoukankan      html  css  js  c++  java
  • German Collegiate Programming Contest 2017 G. Water Testing

    2020-08-12

    You just bought a large piece of agricultural land, but you noticed that – according to regulations– you have to test the ground water at specific points on your property once a year. Luckilythe description of these points is rather simple. The whole country has been mapped using aCartesian Coordinate System (where (0,0) is the location of the Greenwich Observatory). Thecorners of all land properties are located at integer coordinates according to this coordinatesystem. Test points for ground water have to be erected on every point inside a property whosecoordinates are integers.

    输入

    The input consists of:

    • one line with a single integer n(3≤n≤100000), the number of corner points of yourproperty;

    • n lines each containing two integers x and y(−106≤x,y≤106), the coordinates ofeach corner.

    The corners are ordered as they appear on the border of your property and the polygon describedby the points does not intersect itself.

    输出

    The number of points with integer coordinates that are strictly inside your property.

    样例输入

    4
    0 0
    0 10
    10 10
    10 0
    

    样例输出

    81
    

    分析

    皮克定理: S=a+b/2-1 S: 面积,a: 内部点个数,b: 边缘点个数

    多边形面积可以通过向量叉乘算得,注意凹凸多边形。

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <map>
    #include <vector>
    #include <string>
    
    typedef long long LL;
    
    using namespace std;
    
    long long sidepoint (LL x1, LL y1, LL x2, LL y2)
    {
        return __gcd(abs(x1 - x2), abs(y1 - y2));
    }
    
    int main()
    {
        //S=a+b/2-1
        double S = 0;
        long long x1, y1, x2, y2, x3, y3, xt, yt;
        int t;
        scanf("%d", &t);
        scanf("%lld%lld", &x1, &y1);
        scanf("%lld%lld", &x2, &y2);
        long long sp = sidepoint(x1, y1, x2, y2);
        t -= 2;
        while (t--) {
            scanf("%lld%lld", &x3, &y3);
            sp += sidepoint(x2, y2, x3, y3);
            S += double((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1)) / 2;
            x2 = x3;
            y2 = y3;
        }
        sp += sidepoint(x2, y2, x1, y1);
        printf("%.0lf
    ", fabs(S) + 1.0 - sp*1.0/2);
        //printf("%lf %lld %d ", S, sp, t);
        
        return 0;
    }
    

    by SDUST weilinfox

  • 相关阅读:
    最小生成树(prim算法)C语言实现
    图的十字链表存储(C语言)
    打算做一款给方便学生生活的APP,虽然已经有口袋小安了,但是并没有我想要的功能。。。
    腾讯云Ubuntu安装JDK和Tomcat
    新浪微博配图批量下载
    Algorithms in C第一章笔记
    Java笔记
    稍微记录一下effective c++的一些东西
    总结,并加油
    苹果Xcode帮助文档阅读指南
  • 原文地址:https://www.cnblogs.com/weilinfox/p/13491742.html
Copyright © 2011-2022 走看看