G - Water Testing

Problem G 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. Input 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. Output The number of points with integer coordinates that are strictly inside your property.

Sample Input 1

Sample Output 1

4

0 0

0 10

10 10

10 0

就是给你一个多边形,让你求出这个多边形的内部点的坐标是整数的点个数,这个点不包括在多边形边界上面的点

就是给你一个线段,已经知道线段的左右的端点坐标可以在log(abs(x1-x2),abs(y1 - y2))的时间复杂度内将

其求出;

#include <bits/stdc++.h>
using namespace std;
const int Max = 2e5+10;
typedef long long ll;
#define rep(i,s,n)  for(ll i=s;i<=n;i++)
#define per(i,n,s)  for(ll i=n;i>=s;i--)
struct node{
 ll x,y;
}p[Max];
ll gcd(ll a, ll b){
  return b==0 ? a : gcd (b,a%b);
}//皮克定理:多边形的面积 = 多边形内部整点的个数 + 边上正点的个数 / 2 - 1;
int main(){
  int n;
  scanf("%d",&n);
  rep(i,0,n-1){
     scanf("%lld %lld",&p[i].x,&p[i].y);
  }
  ll sum=0;
  rep(i,0,n-1){
     sum+=(p[(i+1)%n].y)*(p[i].x-p[(i+2)%n].x);
  }//这是在求多边形的面积;
  ll ans=0;
  rep(i,0,n-1){
    ans+=gcd(abs(p[i].x-p[(i+1)%n].x),abs(p[i].y-p[(i+1)%n].y));
  }//这是在求边界上面的点
  sum=abs(sum);
  sum=(sum-ans)/2+1;
  printf("%lld\n",sum);
  return 0;
}

21 皮克定理 姿势不对一直wa到死亡相关推荐

  1. poj12652954 [皮克定理 格点多边形]【学习笔记】

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

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

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

  3. POJ 1265-Area(计算几何+皮克定理+多边形面积公式)

    题目地址:POJ 1265 题意:给定一个格点多边形,求出内部点数in,边上点数on,和面积S. 思路:运用的定理很多. 1.皮克定理:S=in+on/2-1,即in=(2*S+2-on)/2. 2. ...

  4. UA MATH563 概率论的数学基础 中心极限定理21 Skorohod定理的证明

    UA MATH563 概率论的数学基础 中心极限定理21 Skorohod定理的证明 Skorohod定理 如果Fn⇒FF_n \Rightarrow FFn​⇒F,则存在以FnF_nFn​为cdf的 ...

  5. Redux 并不慢,只是你使用姿势不对 —— 一份优化指南

    原文地址:Redux 并不慢,只是你使用姿势不对 -- 一份优化指南 原文作者:Julian Krispel 译文出自:掘金翻译计划 本文永久链接:github.com/xitu/gold-m- 译者 ...

  6. Acwing:通电围栏(皮克定理)

    题目描述 农夫约翰的牧场可以看作是一个二维平面. 约翰为了方便看管他养的牛,构建了一个三角形的通电围栏. 他希望他的奶牛都在围栏围起的区域内活动. 三角形围栏的三个顶点位置坐标分别为 (0,0),(n ...

  7. NOJ 1434 Fence (皮克定理)

    Fence 时间限制(普通/Java):1000MS/3000MS         运行内存限制:65536KByte 总提交:59          测试通过:23 题目描述 In this pro ...

  8. Electric Fences_usaco3.4_皮克定理

    Description 给定两个整点(m,n)(m,n)和(p,0)(p,0),与坐标原点(0,0)(0,0)构成三角形,求三角形内的整点数量 Analysis 找到这么一道神奇的题目以及神奇的定理 ...

  9. 三角形的内点(皮克定理)

    题目: 在一个平面坐标系中,我们可以选出三个不全在一条线上的点构成一个三角形.我们称一个在三角形内(不包含三角形的边上),横纵坐标皆为整数的点位这个三角形的内点. 对于一个由(0,0).(n,m).( ...

  10. 为什么你学了几天 STM32 感觉一脸茫然,是你的姿势不对

    为什么你学了几天 STM32感觉一脸茫然,是你的姿势不对 是的,你的感觉没错,其实你自己已经有朦胧的答案,在之前没接触过任何单片机,其实你的问题能够归结于以下几个理由: 1.MCU的根底知识了解的缺少 ...

最新文章

  1. ubunu16.04 TensorFlow object detection API 应用配置
  2. 【Android 应用开发】Google 官方 EasyPermissions 权限申请库 ( 权限申请原理对话框操作回调接口 | 永久拒绝权限后引导设用户置权限 )
  3. Java问题排查工具箱
  4. 商女不知亡国恨,一天到晚敲代码
  5. 让 Ocelot 与 asp.net core “共存”
  6. Oracle入门(十四A)之PL/SQL 基本结构
  7. google now
  8. 机器学习笔记——决策树之回归树
  9. 【面试虐菜】—— MongoDB知识整理
  10. STM32(5)——通用定时器基本定时器
  11. 《C程序设计语言》笔记 目录
  12. 2016中国云计算技术大会精彩PPT干货分享
  13. 自学考试-“运筹学基础”
  14. 使用Javapoet生成代码
  15. 解决excel(日期变数字)导入数据库(数字变日期)
  16. Java 对图片进行大小转换
  17. 三菱四节传送带控制梯形图_三菱plc控制传送带三级 编程 fx2n 模拟四节传送带控制实验三菱...
  18. 2012ESRI中国用户大会有感
  19. Jekyll搭建个人博客 韩俊强的博客
  20. 阅读器的转换功能搬家了,你发现了吗?

热门文章

  1. 《墨宝非宝经典作品合集(套装共10册)》墨宝非宝(作者)epub+mobi+azw3格式下载...
  2. SharpDevelop5.1支持.net4.5.2以上版本
  3. 正确的计算机锁屏方法快捷键,电脑锁屏快捷键?(电脑快速锁屏以及酷炫快速切换窗口的方法!)...
  4. RecyclerView在GridLayoutManager情况下实现四周都有分割线的ItemDecoration
  5. python 聚类 客户细分_KMeans聚类:商城客户细分数据
  6. Python机器学习04——惩罚回归
  7. TK1安装Caffe
  8. DOM事件+正则表达式
  9. 比较有意思的.NET反调—《.NET在蹉跎中一路前行》
  10. java抽象类重载_012 JAVA 抽象类、接口、String类的基础了解