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 ;
}

最新文章

  1. Quartz-2D
  2. 论文笔记之:Deep Recurrent Q-Learning for Partially Observable MDPs
  3. jeesite笔记
  4. ActiveMQ实现负载均衡+高可用部署方案(转)
  5. js类型判断
  6. php下使用phpmailer发送邮件
  7. VMware系统运维(九)VMware vSphere Client 安装
  8. 移动终端学习一:css3 Media Queries简介
  9. 写一个Windows上的守护进程(3)句柄的管理
  10. 视频编辑SDK---我们只提供API,任你自由设计炫酷的功能
  11. HttpRuntime.Cache .Net自带的缓存类
  12. 为链表数据结构实现iterator接口
  13. 55.Vue环境搭建
  14. preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 8
  15. Mordern Effective C++ --auto
  16. 【mongo】登陆报错
  17. CEF 添加F5刷新快捷键
  18. 解题:CTSC 2008 祭祀
  19. mysql批量insert速度超慢
  20. bootstrap带图标的按钮与图标做连接

热门文章

  1. [转载]workbench分网---mapped face meshing面映射网格划分
  2. JAVA基础知识|java虚拟机(JVM)
  3. thymeleaf 直接调用后台Service
  4. legend3---16、网站的安全性问题
  5. PHPStorm 快捷键大全(Win/Linux/Mac)
  6. Messagebox自定义计时关闭
  7. Linux工程管理器——make
  8. world: 对比两个文档
  9. Ionic 的安装运行
  10. ISO/IEC 9899:2011 条款6.2.2——标识符的连接