样例:

输入:
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. 关于Java的File.separator

    在Windows下的路径分隔符和Linux下的路径分隔符是不一样的,当直接使用绝对路径时,跨平台会暴出“No such file or diretory”的异常. 比如说要在temp目录下建立一个te ...

  2. extjs4 树列表 添加子节点 刷新所有父节点数据

    itemclick:function(view, record, item,index){console.log(record.parentNode) for(pNode = record.paren ...

  3. HttpWebResponse返回信息

    CharacterSet "ISO-8859-1" string 获取响应的字符集. 这个目前不知道是干嘛用的 ContentEncoding "" strin ...

  4. Flume协作框架

    1.概述 ->flume的三大功能 collecting, aggregating, and moving 收集 聚合 移动 2.框图 3.架构特点 ->on streaming data ...

  5. Java Socket Option

    选项 public final static int TCP_NODELAY = 0x0001; public final static int SO_REUSEADDR = 0x04; public ...

  6. JVM 常用配置

    JVM的配置,最常用的两个配置就是:-Xms512m –Xmx1024m -Xms设置JVM的初始化内存大小,-Xmx为最大内存大小,当突破这个值,将会报内存溢出,导致的原因有很多,主要是虚拟机的回收 ...

  7. 利用JS脚本通过getAttribute()和setAttribute()等对CSS样式进行操作

    HTML中引入CSS样式的方式有三种: 1.最常用的,引入样式表,在样式表中编写样式,引入方式如下:<link href="css/style.css" rel=" ...

  8. IIS8中部署WCF服务出错:HTTP 错误 404.3 - Not Found

    解决方法,以管理员身份进入命令行模式,运行: "%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ ...

  9. CSS优先级别计算

    a.b.c.d,可以以这四种等级为依据确定CSS选择器的优先级: a-----style 行内样式 个数  +1000 b-----id 个数+100 c-----类 个数+10 d-----类型个数 ...

  10. Internal Server Error500

    开启#LoadModule rewrite_module modules/mod_rewrite.so