Water Testing【皮克定理,多边形面积,线段上点的数目】
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【皮克定理,多边形面积,线段上点的数目】的更多相关文章
- Gym 101873G - Water Testing - [皮克定理]
题目链接:http://codeforces.com/gym/101873/problem/G 题意: 在点阵上,给出 $N$ 个点的坐标(全部都是在格点上),将它们按顺序连接可以构成一个多边形,求该 ...
- Codeforces-GYM101873 G Water Testing 皮克定理
题意: 给定一个多边形,这个多边形的点都在格点上,问你这个多边形里面包含了几个格点. 题解: 对于格点多边形有一个非常有趣的定理: 多边形的面积S,内部的格点数a和边界上的格点数b,满足如下结论: 2 ...
- POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积
题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...
- Area---poj1265(皮克定理+多边形求面积)
题目链接:http://poj.org/problem?id=1265 题意是:有一个机器人在矩形网格中行走,起始点是(0,0),每次移动(dx,dy)的偏移量,已知,机器人走的图形是一个多边形,求这 ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
- POJ 2954 /// 皮克定理+叉积求三角形面积
题目大意: 给定三角形的三点坐标 判断在其内部包含多少个整点 题解及讲解 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 - 1 那么求内部整点就是 in = s + 1 - ...
- 洛谷 P2735 电网 Electric Fences Label:计算几何--皮克定理
题目描述 在本题中,格点是指横纵坐标皆为整数的点. 为了圈养他的牛,农夫约翰(Farmer John)建造了一个三角形的电网.他从原点(0,0)牵出一根通电的电线,连接格点(n,m)(0<=n& ...
- poj1265&&2954 [皮克定理 格点多边形]【学习笔记】
Q:皮克定理这种一句话的东西为什么还要写学习笔记啊? A:多好玩啊... PS:除了蓝色字体之外都是废话啊... Part I 1.顶点全在格点上的多边形叫做格点多边形(坐标全是整数) 2.维基百科 ...
随机推荐
- hadoop(hbase)副本数修改
一.需求场景 随着业务数据的快速增长,物理磁盘剩余空间告警,需要将数据备份从3份修改为1份,从而快速腾出可用磁盘容量. 二.解决方案 1. 修改hdfs的副本数 Hbase 的数据是存储在 hdfs ...
- python—day02_基本数据类型
1,字符串 字符串常用功能: 移除空白 分割 长度 索引 切片 1)移除空白 """S.strip([chars]) -> str Return a copy of ...
- 王艳 201771010127《面向对象程序设计(java)》第九周学习总结
实验九 异常.断言与日志 实验时间 2018-10-25 1.实验目的与要求 (1) 掌握java异常处理技术: (2) 了解断言的用法: (3) 了解日志的用途: (4) 掌握程序基础调试技巧: 一 ...
- 【Java】手把手模拟CAS,瞬间理解CAS的机制
话不多少,先看个案例,[模拟100个用户,每个用户访问10次网站]”: public class ThreadDemo1 { //总访问量 ; //模拟访问的方法 public static void ...
- Understanding closures in depth
什么是闭包 维基百科中的概念 在计算机科学中,闭包(英语:Closure),又称词法闭包(Lexical Closure)或函数闭包(function closures),是在支持头等函数的编程语言中 ...
- Floyd's Triangle
Floyd's Triangle Floyd's triangle is a right-angled triangular array of natural numbers. Floyd's tri ...
- springmvc拦截器和概念,配置!!!
用于拦截请求,过滤后再拦截 实现HandlerInterceptor接口 配置拦截器 package cn.zys.lanjieqi; import javax.servlet.http.HttpSe ...
- [安卓基础] 006.打开另一个Activity
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- [JavaWeb基础] 012.Struts2 自定义标签使用
在做开发中,我们会把一些比较经常使用到的代码封装起来,这样可以加快开发的速度和减少错误,并且在修改bug可以一次修改多次修复.那么在前端页面上,如果我们要经常用到公用的显示功能,并涉及到服务端逻辑操作 ...
- Java IO(三)FileDescriptor
Java IO(三)FileDescriptor 一.介绍 FileDescriptor 是文件描述符,用来表示开放文件.开放套接字等.当 FileDescriptor 表示文件时,我们可以通俗的将 ...