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

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e6+; ll gcd(ll u,ll v){
return (v == 0ll) ? u : gcd(v,u%v);
} typedef struct point{
ll x , y ;
point() {}
point(ll a,ll b):x(a),y(b) {}
void input(){
scanf("%lld%lld",&x,&y);
}
friend point operator + ( const point &a , const point &b ){
return point(a.x + b.x , a.y + b.y );
}
friend point operator - ( const point &a , const point &b ){
return point(a.x - b.x , a.y - b.y );
} }point; point List[maxn];
ll det(const point & a , const point & b){
return a.x * b.y - a.y * b.x ;
} ll Abs( ll x ){
return (x>=?x:-x);
} ll area( point a[] ,int n)
{
ll sum = ;
a[n] = a[] ;
for(int i=; i<n; i++) sum += det(a[i+],a[i]);
return sum ;
}
ll Border_Int_Point_Num( point a[] , int n)
{
ll num = ;
a[n] = a[];
for(int i=; i<n; i++)
{
if( Abs((a[i+].x-a[i].x)) == ){
num += Abs(a[i+].y-a[i].y);
}else if( Abs((a[i+].y-a[i].y)) == ){
num += Abs(a[i+].x-a[i].x);
}else{
num += gcd(Abs(ll(a[i+].x-a[i].x)),Abs(ll(a[i+].y-a[i].y)));
}
}
return num ;
}
ll Inside_Int_Point_Num( point a[] , int n )
{
ll Area = area(a,n) ;
Area = Abs(Area);
return ( Area - Border_Int_Point_Num(a,n) ) / + ; }
//polyon S ; int n;
int main()
{
scanf("%d",&n);
//S.n = n ; for(int i=;i<n;i++)
List[i].input();
/*
sort ( List , List + n , cmp ); for(int i=n-1;i>=0;i--){
S.a[i] = List[n-i-1] ;
} for(int i=0;i<n;i++){
scanf("%lld%lld",&S.a[i].x,&S.a[i].y);
}
*/
printf("%lld\n",Inside_Int_Point_Num(List,n));
return ;
}

【计算几何】Water Testing的更多相关文章

  1. Water Testing【皮克定理,多边形面积,线段上点的数目】

    Water Testing 传送门:链接  来源:UPC 9656 题目描述 You just bought a large piece of agricultural land, but you n ...

  2. Gym 101873G - Water Testing - [皮克定理]

    题目链接:http://codeforces.com/gym/101873/problem/G 题意: 在点阵上,给出 $N$ 个点的坐标(全部都是在格点上),将它们按顺序连接可以构成一个多边形,求该 ...

  3. Codeforces-GYM101873 G Water Testing 皮克定理

    题意: 给定一个多边形,这个多边形的点都在格点上,问你这个多边形里面包含了几个格点. 题解: 对于格点多边形有一个非常有趣的定理: 多边形的面积S,内部的格点数a和边界上的格点数b,满足如下结论: 2 ...

  4. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    A Drawing Borders 很多构造方法,下图可能是最简单的了 代码: #include<bits/stdc++.h> using namespace std; ; struct ...

  5. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) Solution

    A. Drawing Borders Unsolved. B. Buildings Unsolved. C. Joyride Upsolved. 题意: 在游乐园中,有n个游玩设施,有些设施之间有道路 ...

  6. (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)

    layout: post title: (寒假开黑gym)2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017) au ...

  7. The German Collegiate Programming Contest 2017

    B - Building 给一个m各面的多边形柱体,每一侧面有n*n个格子,现在对这些格子染色,看有多少种方式使得多面柱体无论如何旋转都不会与另一个一样. #include <bits/stdc ...

  8. 2017-2018 ACM-ICPC German Collegiate Programming Contest (GCPC 2017)(9/11)

    $$2017-2018\ ACM-ICPC\ German\ Collegiate\ Programming\ Contest (GCPC 2017)$$ \(A.Drawing\ Borders\) ...

  9. ZOJ3238 Water Ring(计算几何)

    题意:给你一个圆形和很多个矩形,然后要你求圆形的圆周有多少被矩形覆盖. 思路:比赛的时候是有思路的了,不过一直在调别的题,最后剩下30分钟肯定来不及敲.想法是这样的,要是我们可以求出每个矩形覆盖了圆周 ...

随机推荐

  1. 已安装gcc编译器,但./configure还是提示找不到编译器(分析)

    1.编译nginx前, ./configure检查提示找不到C编译器 [root@test nginx-]# ./configure checking for OS + Linux -.el7.x86 ...

  2. 如何在vue-cli 3.x中使用jquery

    由于项目需求要使用jquery,结果各种引用都不济于事. 最后在网上找到了答案,现把它记录一下,给有需要者. 首先下载 jquery. cnpm install jquery --save-dev 方 ...

  3. python 了解一下__dict__

    写在前面 这几天在写关于描述器的博客,在了解描述器的机制的时候,翻了很多博客里面都提到了__dict__, 我想更多的了解一点描述器的机制,所以我得先弄清楚这个__dict__到底是干啥的. 计算机语 ...

  4. android DownloadManager: java.lang.IllegalArgumentException: Not a file URI: content://

    DownloadManager 使用Uri指定下载路径Bug 使用DownloadManager 下载文件 通常写法: DownloadManager dm = (DownloadManager) g ...

  5. 【集成模型】Stacking

    0 - 思路 Stacking是许多集成方法的综合.其主要思路如下图所示,通过训练数据训练多个base learners(the first-level learners),这些learners的输出 ...

  6. 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_06-用户认证-认证服务查询数据库-Bcrypt介绍

    演示MD5加密的方式 数据库内的数据密码虽然都是6个1但是 每次加密出来的字符串是不一样的 加盐 测试BCrpty 循环10次加密 密码的校验 比人工的加盐要方便的多 这是创建的一个Spring的Be ...

  7. 最简单的freemarker用法实例

          1.下载freemarker-2.3.19.jar到web项目的lib下. 2.新建freemarker引擎协助类 package com.bxsurvey.sys.process.uti ...

  8. selenium chromedriver与chrome版本对应表

    chromedriver版本   支持的Chrome版本 v2.41               v67-69 v2.40               v66-68 v2.39             ...

  9. 【Leetcode_easy】661. Image Smoother

    problem 661. Image Smoother 题意:其实类似于图像处理的均值滤波. solution: 妙处在于使用了一个dirs变量来计算邻域数值,看起来更简洁! class Soluti ...

  10. react中异步的使用

    let promise; promise = this.props.corporationService.preSearchPage(params); promise.then((data) => ...