样例:

输入:
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
*/

UVa 10088 - Trees on My Island (pick定理)的更多相关文章

  1. LightOJ 1418 Trees on My Island (Pick定理)

    题目链接:LightOJ 1418 Problem Description I have bought an island where I want to plant trees in rows an ...

  2. UVa 10088 (Pick定理) Trees on My Island

    这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...

  3. HDU 3775 Chain Code ——(Pick定理)

    Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...

  4. 【POJ】2954 Triangle(pick定理)

    http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...

  5. Area(Pick定理POJ1256)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5429   Accepted: 2436 Description ...

  6. poj 2954 Triangle(Pick定理)

    链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS   Memory Limit: 65536K Total Submissio ...

  7. poj 1265 Area (Pick定理+求面积)

    链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

  8. poj1265Area(pick定理)

    链接  Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一. pick定理的一些应用 题意不好懂, ...

  9. pick定理:面积=内部整数点数+边上整数点数/2-1

    //pick定理:面积=内部整数点数+边上整数点数/2-1 // POJ 2954 #include <iostream> #include <cstdio> #include ...

随机推荐

  1. cascading rollback 级联回滚

    Computer Science An Overview _J. Glenn Brookshear _11th Edition To emphasize the delicate nature of ...

  2. 浅析C++的内存管理

    在C++中,内存分成5个区,他们分别是堆.栈.自由存储区.全局/ 静态存储区和常量存储区. 栈,就是那些由编译器在需要的时候分配,在不需要的时候自动清楚的变量的存储区.里面的变量通常是局部变量.函数参 ...

  3. oracle utf8字符集转gbk(转)

    近日有同事在外面部署系统时,安装数据库时可能选择了UTF-8编码格式,导入insert语句时,一个汉字被认为三个字节,这是不行的. 结合上网搜到的资料,将oracle数据库的编码格式,从utf-8改为 ...

  4. 【转】设计模式 ( 十八 ) 策略模式Strategy(对象行为型)

    设计模式 ( 十八 ) 策略模式Strategy(对象行为型) 1.概述 在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成 ...

  5. sqlserver 计算 百分比

    ,),))+'%' As 百分比 NUMERIC(P,S) P的默认值是:38 S的默认值是:-84~127 numeric(a,b)函数有两个参数,前面一个为总的位数,后面一个参数是小数点后的位数, ...

  6. BeanUtils 学习教程

    what happens in more sophisticated environments where you do not necessarily know ahead of time whic ...

  7. 常用jQuery代码02

    一.each函数拿到每个元素的宽度 setTimeout(function () { $(".sticker_list img").each(function () { var W ...

  8. CodeMIrror 简单使用

    代码高亮是程序员的刚需,不管是在笔记类,论坛类,博客类web网站中,都对代码高亮提出要求,不高亮的代码阅读体验很差,codeMirror是一个前端代码高亮库,使用方便. codeMirror可以直接在 ...

  9. HTML5中表单的创建

    一.常用表单标签如下: (1)<input>中的“type”属性: 复选框-checkbox:单选按钮-radio;按钮-button:提交-submit; (2)文本域 行-cols:列 ...

  10. Java学习-026-类名或方法名应用之二 -- 统计分析基础

    前文讲述了类名或方法的应用之一调试源码,具体请参阅:Java学习-025-类名或方法名应用之一 -- 调试源码 此文主要讲述类名或方法应用之二统计分析,通过在各个方法中插桩(调用桩方法),获取方法的调 ...