Water Testing

传送门:链接  来源:UPC 9656

题目描述

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

题目大意:

给出一个多边形每个顶点的坐标,求在该图形内部方格点的个数。

解题思路:

`1、皮克定理:2S=b+2a-2   (其中S表示多边形的面积,b表示多边形上点的个数,a表示多边形内部点的个数。)

2、已知顶点坐标求多边形面积公式:S=0.5*abs(x1*y2-y1*x2+x2*y3-y2*x3+...+xn*y1-yn*x1)

3、已知方向向量为(x,y)求在线段上点的个数:b=gcd(fabs(x),fabs(y))

如果(x1,y1)只是一个顶点而不是向量,就要先求出边的向量才能用公式3!!!

根据上面三个公式可以求出: b=S-1+0.5*a

qi shi shu lun bu gui wo guan !

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX=1e5;
struct point{
double x;
double y;
}p[MAX+5];
LL gcd(LL a,LL b)
{
if(b==0) return a;
return gcd(b,a%b);
}
int main()
{
LL n;
cin>>n;
double s=0,b=0;
for(LL i=0;i<n;i++){
cin>>p[i].x>>p[i].y;
if(i!=0){
b+=gcd(fabs(p[i].x-p[i-1].x),fabs(p[i].y-p[i-1].y));
s+=(p[i].y*p[i-1].x-p[i].x*p[i-1].y);
}
}
s+=(p[0].y*p[n-1].x-p[0].x*p[n-1].y);
b+=gcd(fabs(p[0].x-p[n-1].x),fabs(p[0].y-p[n-1].y));
s=0.5*fabs(s);
cout<<(LL)(s+1-b*0.5)<<endl;
return 0;
}

Water Testing【皮克定理,多边形面积,线段上点的数目】的更多相关文章

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

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

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

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

  3. POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积

    题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...

  4. Area---poj1265(皮克定理+多边形求面积)

    题目链接:http://poj.org/problem?id=1265 题意是:有一个机器人在矩形网格中行走,起始点是(0,0),每次移动(dx,dy)的偏移量,已知,机器人走的图形是一个多边形,求这 ...

  5. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  6. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  7. POJ 2954 /// 皮克定理+叉积求三角形面积

    题目大意: 给定三角形的三点坐标 判断在其内部包含多少个整点 题解及讲解 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 - 1 那么求内部整点就是 in = s + 1 - ...

  8. 洛谷 P2735 电网 Electric Fences Label:计算几何--皮克定理

    题目描述 在本题中,格点是指横纵坐标皆为整数的点. 为了圈养他的牛,农夫约翰(Farmer John)建造了一个三角形的电网.他从原点(0,0)牵出一根通电的电线,连接格点(n,m)(0<=n& ...

  9. poj1265&&2954 [皮克定理 格点多边形]【学习笔记】

    Q:皮克定理这种一句话的东西为什么还要写学习笔记啊? A:多好玩啊... PS:除了蓝色字体之外都是废话啊...  Part I 1.顶点全在格点上的多边形叫做格点多边形(坐标全是整数) 2.维基百科 ...

随机推荐

  1. jquery-ui-i18n.js源码

    /* Afrikaans initialisation for the jQuery UI date picker plugin. */ /* Written by Renier Pretorius. ...

  2. MySQL(7)— 索引

    七.索引 MySQL官方对索引的定义为:索引(Index)是帮助 MySQL 高效 获取数据的数据结构. 7-1.索引的分类 主键索引 (primary key) 唯一的标识,主键不可重复,只能有一个 ...

  3. BZOJ1022

    1022: [SHOI2008]小约翰的游戏John Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 2701  Solved: 1721[Submit] ...

  4. Pyqt5_QLabel

    QLabel 作用 方法 信号 作用 占位符.显示文本.显示图片.放置gif动画.超链接.提示标记 方法 setAlignment() 按固定值方式对齐文本 Qt.AlignLeft:水平方向靠左对齐 ...

  5. python之module 'unittest' has no attribute 'TestCase' 解决方案

    脚本报错如下:  解决方案: 这是脚本名称冲突所导致的报错,修改脚本名中重新执行,运行正常 注:脚本取名最好不要与模块和方法一致,避免不必要的冲突

  6. SQL——SQL函数

    avg(col) -- 返回数值列的平均值,NULL值不包括在计算中.count(col) -- 返回指定列的值的数目,NULL不计入:count(*)返回表中记录数:count(distinct c ...

  7. JVM调优总结(七)-调优方法

    JVM调优工具 Jconsole,jProfile,VisualVM Jconsole : jdk自带,功能简单,但是可以在系统有一定负荷的情况下使用.对垃圾回收算法有很详细的跟踪.详细说明参考这里 ...

  8. Java中的自动装箱拆箱

    Java中的自动装箱拆箱 一.自动装箱与自动拆箱 自动装箱就是将基本数据类型转换为包装类类型,自动拆箱就是将包装类类型转换为基本数据类型. 1 // 自动装箱 2 Integer total = 90 ...

  9. Parrot os更新内核及/boot空间清理

    升级时发现boot,空间满了,卸载以前的内核,清理空间. 如何升级内核请查看我上篇博客:https://www.cnblogs.com/junsec/p/11453049.html 卸载多余内核,清理 ...

  10. 最小生成树——Kruskal算法理解

    背景:本文是在小甲鱼数据结构教学视频中的代码的基础上,添加详细注释而完成的.该段代码并不完整,仅摘录了核心算法部分,结合自己的思考,谈谈理解. Prim算法理解: 如图(摘录自小甲鱼教学视频中的图片) ...