zoukankan      html  css  js  c++  java
  • 【计算几何】Water Testing

    Water Testing

    题目描述

    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. Luckily the description of these points is rather simple. The whole country has been mapped using a Cartesian Coordinate System (where (0, 0) is the location of the Greenwich Observatory). The corners of all land properties are located at integer coordinates according to this coordinate system. Test points for ground water have to be erected on every point inside a property whose coordinates are integers.

    输入

    The input consists of:
    • one line with a single integer n (3 ≤ n ≤ 100 000), the number of corner points of your property;
    • n lines each containing two integers x and y (−106 ≤ x, y ≤ 106 ), the coordinates of each corner.
    The corners are ordered as they appear on the border of your property and the polygon described by 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



    【题解】

    皮克定理模版题,大家注意,面积可能在点乘的时候是负数。

    还需要开Long Long

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 const int maxn = 2e6+50;
     5  
     6 ll gcd(ll u,ll v){
     7     return (v == 0ll) ? u : gcd(v,u%v);
     8 }
     9  
    10 typedef struct point{
    11     ll x , y ;
    12     point() {}
    13     point(ll a,ll b):x(a),y(b) {}
    14     void input(){
    15         scanf("%lld%lld",&x,&y);
    16     }
    17     friend point operator + ( const point &a , const point &b ){
    18         return point(a.x + b.x , a.y + b.y );
    19     }
    20     friend point operator - ( const point &a , const point &b ){
    21         return point(a.x - b.x , a.y - b.y );
    22     }
    23  
    24 }point;
    25  
    26  
    27  
    28 point List[maxn];
    29 ll det(const point & a , const point & b){
    30     return a.x * b.y - a.y * b.x ;
    31 }
    32  
    33  
    34 ll Abs( ll x ){
    35     return (x>=0?x:-x);
    36 }
    37  
    38  
    39 ll area( point a[] ,int n)
    40 {
    41     ll sum = 0 ;
    42     a[n] = a[0] ;
    43     for(int i=0; i<n; i++) sum += det(a[i+1],a[i]);
    44     return sum ;
    45 }
    46 ll Border_Int_Point_Num( point a[] , int n)
    47 {
    48     ll num = 0 ;
    49     a[n] = a[0];
    50     for(int i=0; i<n; i++)
    51     {
    52         if( Abs((a[i+1].x-a[i].x)) == 0  ){
    53             num += Abs(a[i+1].y-a[i].y);
    54         }else if( Abs((a[i+1].y-a[i].y)) == 0 ){
    55             num += Abs(a[i+1].x-a[i].x);
    56         }else{
    57             num += gcd(Abs(ll(a[i+1].x-a[i].x)),Abs(ll(a[i+1].y-a[i].y)));
    58         }
    59     }
    60     return num ;
    61 }
    62 ll Inside_Int_Point_Num( point a[] , int n )
    63 {
    64     ll Area = area(a,n) ;
    65     Area = Abs(Area);
    66     return ( Area - Border_Int_Point_Num(a,n) ) / 2 + 1 ;
    67  
    68 }
    69 //polyon S ;
    70  
    71 int n;
    72 int main()
    73 {
    74     scanf("%d",&n);
    75     //S.n = n ;
    76  
    77     for(int i=0;i<n;i++)
    78         List[i].input();
    79     /*
    80     sort ( List , List + n , cmp );
    81  
    82     for(int i=n-1;i>=0;i--){
    83         S.a[i] = List[n-i-1] ;
    84     }
    85  
    86     for(int i=0;i<n;i++){
    87         scanf("%lld%lld",&S.a[i].x,&S.a[i].y);
    88     }
    89     */
    90     printf("%lld
    ",Inside_Int_Point_Num(List,n));
    91     return 0;
    92 }
    View Code
  • 相关阅读:
    阿里云服务器搭建之绑定多个域名
    centos7下yum安装mysql
    Mac 升级之后 无法通过域名 SSH 连接
    【课程章节更新】突破 没有支付权限的小程序 完成支付闭环
    每次sudo su切换root用户,都要source /etc/profile
    那些让你震惊的网站
    bootstrap select2使用模态框,搜索框无法输入问题解决
    新浪图片停止外链后的一些解决办法
    Yii2 报错 Headers already sent in
    使用Python Flask 开发微信机器人
  • 原文地址:https://www.cnblogs.com/Osea/p/11397596.html
Copyright © 2011-2022 走看看