样例:

输入:
12
3 1
6 3
9 2
8 4
9 6
9 9
8 9
6 5
5 8
4 4
3 5
1 3
12
1000 1000
2000 1000
4000 2000
6000 1000
8000 3000
8000 8000
7000 8000
5000 4000
4000 5000
3000 4000
3000 5000
1000 3000
4
0 0
1000000 0
1000000 1000000
0 1000000
4
0 0
100 0
100 100
0 100

输出:

21

25990001

999998000001

9801

分析:Pick定理:一个计算点阵中顶点在格点上的多边形面积公式:S=a+b/2.0-1,其中a表示多边形内部的点数,b表示多边形边界上的点数,s表示多边形的面积。

首先利用叉积求多边形的面积S;

然后求出b,方法是枚举每条边,然后以改边构成一个直角三角形,直角边长度是n,m,斜边上有的整数点的个数是gcd(n,m)-1(不包括两端点)最后b=b+n;

即可

最后a=S+1-b/2.0;

需要注意的地方是:a可能爆int

 #include"stdio.h"
#include"string.h"
#include"algorithm"
#include"stdlib.h"
#include"math.h"
#include"map"
#include"queue"
#include"iostream"
#define M 1009
#define inf 0x3f3f3f3f
#define eps 1e-9
using namespace std;
struct node
{
double x,y;
node(){}
node(double x,double y)
{
this->x=x;
this->y=y;
}
node operator-(node a)
{
return node(x-a.x,y-a.y);
}
node operator+(node a)
{
return node(x+a.x,y+a.y);
}
double operator*(node a)
{
return x*a.x+y*a.y;
}
double operator^(node a)
{
return x*a.y-y*a.x;
}
}p[M];
double len(node a)
{
return sqrt(a*a);
}
double dis(node a,node b)
{
return len(b-a);
}
double cross(node a,node b,node c)
{
return (b-a)^(c-a);
}
int gcd(int a,int b)
{
return b==?a:gcd(b,a%b);
}
int point(node a,node b)
{
int m=(int)(fabs(b.x-a.x)+0.5);
int n=(int)(fabs(b.y-a.y)+0.5);
int r=gcd(m,n);
return r-;
}
int main()
{
int n;
while(scanf("%d",&n),n)
{
for(int i=;i<n;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
double sum=;
node O(,);
double num=n;
for(int i=;i<n;i++)
{
num+=point(p[i],p[(i+)%n]);
sum+=cross(O,p[i],p[(i+)%n]);
}
sum=fabs(sum)/2.0;
double ans=sum+-0.5*num;
printf("%.0f\n",ans+0.001);
}
return ;
}
/*
12
3 1
6 3
9 2
8 4
9 6
9 9
8 9
6 5
5 8
4 4
3 5
1 3
12
1000 1000
2000 1000
4000 2000
6000 1000
8000 3000
8000 8000
7000 8000
5000 4000
4000 5000
3000 4000
3000 5000
1000 3000
4
0 0
1000000 0
1000000 1000000
0 1000000
4
0 0
100 0
100 100
0 100
*/

最新文章

  1. 当前不会命中断点。源代码与原始版本不同 (VS2012)
  2. MySQL ERROR 1045 (28000): Access denied for user &#39;root&#39;@&#39;localhost&#39; (using password: NO) 的解决办法和原因
  3. codeforces 484E
  4. android-ImageView及其子类
  5. c# SQL CLR 之一
  6. 树状数组(二维):COGS 1532 [IOI2001]移动电话
  7. 用python实现对图像的卷积(滤波)
  8. Django_项目初始化
  9. SQL SELECT DISTINCT 语句
  10. 激活miniconda2环境,出现activate命令不存在的解决方案(activate: No such file or directory)
  11. 清楚理解const_cast类型转换
  12. 将 GitHub 上的代码向 Coding 更新
  13. Multiresolution Analysis(多分辨率分析)
  14. linux下mysql的远程访问
  15. Expo大作战(二十三)--expo中expo kit 高级属性(没干货)
  16. Rabbit简单测试实例
  17. Linux strace命令详解
  18. 读书笔记--C陷阱与缺陷(五)
  19. Scrapyd-Client的安装
  20. 解数独(Python)

热门文章

  1. software glue Middleware
  2. RESTful 架构理解
  3. 关于Java中文乱码与日期格式
  4. Nginx 禁用IP IP段
  5. docker jenkins
  6. Linux学习之CentOS(十)--虚拟机下的CentOS如何上网
  7. 七步实现magento迁移
  8. [LeetCode]题解(python):083 - Remove Duplicates from Sorted List
  9. Excel 的一些用法--行号赋给一列
  10. oracle 条件语句的写法