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. 201771010117马兴德 实验二 Java基本程序设计(1)

    实验二 Java基本程序设计(1)  第一部分    理论知识的学习. 第三章Java基本程序设计结构 1  基本知识: (1)标识符:标识符由字母.下划线.美元符号和数字组成,且第一个符号不能为数字 ...

  2. 浅析String、StringBuilder、StringBuffer

    谈谈我对 String.StringBuilder.StringBuffer 的理解 StringBuilder.StringBuffer 和 String 一样,都是用于存储字符串的. 1.那既然有 ...

  3. 【python爬虫】scrapy入门1--环境搭建

    Scrapy Day01 (1) 进入主目录,右键打开终端,创建项目 scrapy startproject xicidailiSpyder 进入项目目录 cd xicidailiSpyder/ 创建 ...

  4. SpringMVC笔记总结

    文章所有代码见:gitee 1.回顾MVC 1.1.什么是MVC MVC是模型(Model).视图(View).控制器(Controller)的简写,是一种软件设计规范. 是将业务逻辑.数据.显示分离 ...

  5. 详解python操作生成excel表格,并且填充数据

    最近在研究python操作excel表格的问题,首先读取excel表格觉得平时用的多,不怎么有难度,就是pyhon生成excel表格的时候,平时不怎么用,所以重点研究了一下,现总结如下: 1.首先用到 ...

  6. 【转】shell的反引号、单引号、双引号的作用

    Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...

  7. 开心一下-实现一个基于Java的中文编程语言2

    https://mp.weixin.qq.com/s/VmCTvh0c7X9DjIgIMycdlw   上一篇所提到的只是使用中文写Java,而不能算作一门新的语言.作为一门中文语言,需要语言提供的关 ...

  8. Rocket - util - ECC

    https://mp.weixin.qq.com/s/yato1PrnHe517J8twgZFOg   介绍ECC(Error Correcting Code/Error Checking and C ...

  9. css背景图定位和浮动

    网站图标引入:<link rel="shortcut icon" href="ico图标地址"> 背景图片  background-image: u ...

  10. Java实现 LeetCode 479 最大回文数乘积

    479. 最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x ...