pick公式:多边形的面积=多边形边上的格点数目/2+多边形内部的格点数目-1。

多边形边上的格点数目可以枚举每条边求出。如果是水平或者垂直,显然可以得到,否则则是坐标差的最大公约数减1.(注这里是不计算端点的,端点必然在格点上,最后统计)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
#include <sstream>
#include <queue>
#include <vector>
#define MAXN 111111
#define MAXM 211111
#define PI acos(-1.0)
#define eps 1e-8
#define INF 1000000001
using namespace std;
int dblcmp(double d)
{
if (fabs(d) < eps) return 0;
return d > eps ? 1 : -1;
}
struct point
{
double x, y;
point(){}
point(double _x, double _y):
x(_x), y(_y){};
void input()
{
scanf("%lf%lf",&x, &y);
}
double dot(point p)
{
return x * p.x + y * p.y;
}
double distance(point p)
{
return hypot(x - p.x, y - p.y);
}
point sub(point p)
{
return point(x - p.x, y - p.y);
}
double det(point p)
{
return x * p.y - y * p.x;
}
bool operator < (point a)const
{
return dblcmp(a.x - x) == 0 ? dblcmp(y - a.y) < 0 : x < a.x;
} }p[MAXN]; int n;
double getarea()
{
double res = 0;
for(int i = 1; i < n; i++) res += p[i].sub(p[0]).det(p[i + 1].sub(p[0]));
res = fabs(res) / 2;
return res;
}
int getinedge()
{
int ans = 0;
for(int i = 1; i <= n; i++)
{
int x = (int)fabs(p[i].x - p[i - 1].x);
int y = (int)fabs(p[i].y - p[i - 1].y);
if(x == 0 && y == 0) continue;
if(x == 0) ans += y - 1;
else if(y == 0) ans += x - 1;
else ans += __gcd(x, y) - 1;
}
return ans + n;
}
int main()
{
int T;
double x, y;
int cas = 0;
scanf("%d", &T);
while(T--)
{
scanf("%d", &n);
p[0].x = 0, p[0].y = 0;
for(int i = 1; i <= n; i++)
{
scanf("%lf%lf", &x, &y);
p[i].x = p[i - 1].x + x;
p[i].y = p[i - 1].y + y;
}
double area = getarea();
int inedge = getinedge();
int inside = (int)area + 1 - inedge / 2;
printf("Scenario #%d:\n%d %d %.1f\n\n",++cas, inside, inedge, area);
}
return 0;
}

POJ 1265 pick定理的更多相关文章

  1. Area POJ - 1265 -皮克定理-叉积

    Area POJ - 1265 皮克定理是指一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2, 其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积. ...

  2. poj 1265&&poj 2954(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5811   Accepted: 2589 Description ...

  3. POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积

    题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...

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

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

  5. POJ 1265 Area (Pick定理 & 多边形面积)

    题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...

  6. POJ 1265 Area POJ 2954 Triangle Pick定理

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5227   Accepted: 2342 Description ...

  7. poj 1265 Area(Pick定理)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5666   Accepted: 2533 Description ...

  8. poj 1265 Area(pick定理)

    Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...

  9. [poj 1265]Area[Pick定理][三角剖分]

    题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...

随机推荐

  1. BZOJ1712 : [Usaco2007 China]Summing Sums 加密

    设$s[i]$为进行$i$次加密后所有奶牛数字的和,有$s[i]=(n-1)s[i-1]$. 设$c[i]$为某头固定的奶牛进行$i$次加密后的数字, 若$i$为奇数,有: \[c[i]=((1-n) ...

  2. ZOJ 2975 Kinds of Fuwas

    K - Kinds of Fuwas Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu De ...

  3. 七层负载(Application Gateway)+四层负载(LB)

    上次有个电商客户需要搭建如架构. 192.168.1.100/url1(请求url)——>Node1:10.0.0.4.10.0.0.5(服务器IP) 192.168.1.100/url2(请求 ...

  4. myeclipse和eclipse的区别和联系,以及版本间的对应关系

    Eclipse:IBM花了4千万美金来开发这个IDE(Integrated Development Environment).第一版1.0在2001年11月释出,随后逐渐受到欢迎.Eclipse已经成 ...

  5. java ffmpeg视频转码(自测通过)

    import java.io.*; public class VideoTransfer { //ffmepg文件 安装目录 private static String ffmpeg = " ...

  6. 理解 HTTPS 协议

    英文原文:Understanding HTTPS Protocol 最近我们看到很多站点使用 HTTPS 协议提供网页服务.通常情况下我们都是在一些包含机密信息的站点像银行看到 HTTPS 协议. 如 ...

  7. clientX, clientY,offsetX, offsetY,screenX, screenY, x, y

    clientX, clientY是鼠标当前相对于网页的位置,当鼠标位于页面左上角时clientX=0, clientY=0: offsetX, offsetY是鼠标当前相对于网页中的某一区域的位置,当 ...

  8. Linux内核:分析coredump文件 - 内核代码崩溃

    转自:http://blog.csdn.net/guowenyan001/article/details/12975221 一.分析Core文件 1.1 找到core文件目录,启动mycrash:my ...

  9. 百度搜索推出惊雷算法严厉打击刷点击作弊行为-SEO公司分享

    百度搜索推出惊雷算法严厉打击刷点击作弊行为 2017年11月20日凌晨,百度搜索引擎发布更新惊雷算法旨在打击刷点击作弊行为. 下面是惊雷算法相关新闻报道: 百度搜索将于11月底推出惊雷算法,严厉打击通 ...

  10. linux下memcached安装 和redis安装,jdk,tomcat,mysql 安装

    一.memcached安装yum  search  memcachedyum  -y install memcachedmemmcached -h service memcached restartc ...