POJ 1265 pick定理
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定理的更多相关文章
- Area POJ - 1265 -皮克定理-叉积
Area POJ - 1265 皮克定理是指一个计算点阵中顶点在格点上的多边形面积公式,该公式可以表示为2S=2a+b-2, 其中a表示多边形内部的点数,b表示多边形边界上的点数,S表示多边形的面积. ...
- poj 1265&&poj 2954(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5811 Accepted: 2589 Description ...
- POJ 1265 /// 皮克定理+多边形边上整点数+多边形面积
题目大意: 默认从零点开始 给定n次x y上的移动距离 组成一个n边形(可能为凹多边形) 输出其 内部整点数 边上整点数 面积 皮克定理 多边形面积s = 其内部整点in + 其边上整点li / 2 ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
- poj 1265 Area(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5666 Accepted: 2533 Description ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- [poj 1265]Area[Pick定理][三角剖分]
题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...
随机推荐
- Nancyfx框架在传统Webform项目中的应用
最近有个老项目需要做一个需求更迭,老项目是基于传统的webform项目的 为了更好的前后台交互,决定引入Nancyfx框架 关于Nancyfx框架框架是啥就不多介绍了 总的来说是一款轻量级的web框架 ...
- 鸟哥的Linux私房菜 基础学习篇读书笔记(9):Linux磁盘与文件系统管理(2)
上一篇文章主要从理论上分析了Linux的Ext2文件系统.这一篇主要解说怎样查看Linux的文件系统的容量以及解说Linux文件系统中的连接文件. 能够通过df和du命令来查看磁盘与文件夹的容量.df ...
- STM32F4 -- How to use the DMA burst feature
Bits 15:13 Reserved, must be kept at reset value. Bits 12:8 DBL[4:0]: DMA burst length This 5-bit ve ...
- Magent搭建Memcached集群
原文地址:http://ultrasql.blog.51cto.com/9591438/1636374 Memcached集群介绍 由于Memcached服务器与服务器之间没有任何通讯,并且不进行任何 ...
- 网站前端优化技术 BigPipe分块处理技术
前端优化已经到极致了么?业务还在为看到不停的而揪心么?还在为2秒率不达标苦恼么? 好吧我知道答案,大家一如既往的烦恼中... 那么接下来我们看看,facebook,淘宝,人人网,一淘都是怎么做前端优化 ...
- Vue 插件写法
都说Vue2简单,上手容易,但小马过河,自己试了才晓得,除了ES6语法和webpack的配置让你感到陌生,重要的是思路的变换,以前随便拿全局变量和修改dom的锤子不能用了,变换到关注数据本身.vue的 ...
- WebLogic使用总结(二)——WebLogic卸载
一.WebLogic 12c的卸载 WebLogic的卸载是非常容易的,找到WebLogic的卸载程序,如下图所示: 启动卸载程序,如下图所示:
- 能在xcode5中开发基于IOS7sdk的应用程序兼容ios4.3之后的系统吗?
能在xcode5中开发基于IOS7sdk的应用程序兼容ios4.3之后的系统吗?
- C#编程(二十五)----------接口
接口 如果一个类派生自一个接口,声明这个类就会实现某些函数.并不是所有的面向对象的语言都支持接口. 例如,有一个接口:IDispoable,包含一个方法Dispose(),该方法又类实现,用于清理代码 ...
- 如何调试 Android 上 HTTP(S) 流量
http://greenrobot.me/devpost/how-to-debug-http-and-https-traffic-on-android/ 如何调试 Android 上 HTTP(S) ...