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. [Codeforces1137F]Matches Are Not a Child's Play——LCT+树状数组

    题目链接: [Codeforces1137F]Matches Are Not a Child's Play 题目大意: 我们定义一棵树的删除序列为:每一次将树中编号最小的叶子删掉,将该节点编号加入到当 ...

  2. VSCode前端文件(html文件)如何以服务器模式打开?

    方法1: VSCode前端文件(html文件)如何以服务器模式打开?比如工程下有一个A.html文件,想在VSCode里面直接操作,就想Webstorm一样,以http://localhost/xxx ...

  3. Flask上下文源码分析(一)

    flask中的上下文分两种,application context和request context,即应用上下文和请求上下文.   从名字上看,可能会有误解,认为应用上下文是一个应用的全局变量,所有请 ...

  4. golang通过ssh实现远程文件传输

    使用ssh远程操作文件, 主要是创建ssh, 直接上代码 import ( "fmt" "github.com/pkg/sftp" "golang.o ...

  5. arcgis python 布局视图中文本查找替换

    # Author: ESRI # Date: July 5, 2010 # Version: ArcGIS 10.0 # Purpose: This script will perform a sea ...

  6. MediaPlayer: MediaPlayer中的prepare方法和prepareAsync方法的区别

    prepare方法是将资源同步缓存到内存中,一般加载本地较小的资源可以用这个,如果是较大的资源或者网络资源建议使用prepareAsync方法,异步加载.但如果想让资源启动,即start()起来,因为 ...

  7. Elasticsearch .net 记录-1

    简介 ElasticSearch是一个开源的分布式搜索引擎,具备高可靠性,支持非常多的企业级搜索用例.像Solr4一样,是基于Lucene构建的.支持时间时间索引和全文检索.官网:http://www ...

  8. oracle数据库死锁原因及分析

    定义: 当两个用户希望持有对方的资源时就会发生死锁. 即两个用户互相等待对方释放资源时,oracle认定为产生了死锁,在这种情况下,将以牺牲一个用户作为代价,另一个用户继续执行,牺牲的用户的事务将回滚 ...

  9. PHP实现简单留言板

    最近学习了下PHP基础,这里做一个简单的留言板,算是对PHP和MySQL的使用做一个整体的练习吧,不遇到问题总感觉学不到东西. 截图如下: 总结: 1>数据库的简单操作,数据库的增删改查: 2. ...

  10. 关于类似QQ的展开和折叠效果的实现

    介绍: 1.两级折叠与展开: 实现原理如下: 1>通过表视图的组的头视图和单元格实现; 2>通过改变cell的高度实现; 3>通过cell实现; 实现 UITableView 的ce ...