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. An easy problem(hdu2055)

    输入格式:一个整型,然后循环输入一个字符加一个整型. 思考:首先用scanf_s()函数输入整型.然后一个大循环,用scanf_s()函数同时输入字符和整型.第一个scanf_s()函数后,后面还要输 ...

  2. 从零开始搭建一个PaaS平台 - 我们要做什么

    前言 从最开始的小公司做小网站,到现在进入现在的公司做项目,发现小公司里很多很多工作都是重复的劳动(增删改查),不过想想也是,业务软件最基础的东西不就是增删改查吗. 但是很多时候,这种业务逻辑其实没有 ...

  3. mysql新

    .数据库服务器:运行数据库管理软件的计算机 .数据库管理软件:MySQL,oracle,db2,sqlserver .库:文件夹 .表:文件 .记录:事物的一系列典型特征:name,age,schoo ...

  4. java对数据库性能测试

    package com.mysql; import java.sql.Connection; import java.sql.DriverManager; import java.sql.Prepar ...

  5. NO.1 MSP-ESP432P4111开箱

    本人准备2020TI杯模拟电子邀请赛,预计参赛可能会使用TI平台,故从某宝购置一块MSP-ESP432P4111 LaunchPad为参赛做准备.TI官网40美刀,但我只能找国内二道贩子买,有点小贵& ...

  6. JVM调优总结(二)-基本垃圾回收算法

    可以从不同的的角度去划分垃圾回收算法: 按照基本回收策略分 引用计数(Reference Counting): 比较古老的回收算法.原理是此对象有一个引用,即增加一个计数,删除一个引用则减少一个计数. ...

  7. [代码片段-C#]工具代码片段 及 版本信息等

    标题: [SD.TEAM]XXXX 公司: 宝宝巴士(福建)网络科技有限公司 商标: 宝宝巴士 版权: © Babybus SD.Team 版权+作者(简): © Babybus SD.Team - ...

  8. 微软:悬赏10万美金破解 Linux 系统

    微软选择了 Linux 系统作为物联网平台,并且悬赏10万美金邀请黑客来进行破解. 当然,该悬赏计划不是针对所有的 Linux 系统,而是特别针对微软的物联网端对端安全平台Azure Sphere.本 ...

  9. debug PHP程序(xdebug、IntelliJ IDEA)

    之前写PHP程序的都是echo调试,今天感觉太麻烦了就想起研究一下IntelliJ IDEA如何调试PHP程序. 从网上查找了很多资料,大部分都提到在IDE里开启服务,一下就懵了,怎么启这么多服务呢. ...

  10. XXE漏洞学习1

    1.test.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ANY [ <! ...