Area(pick定理)
http://poj.org/problem?id=1265
题意:起始为(0,0),给出每个点的偏移量,求依次连接这些点形成的多边形边界上格点的个数。
思路:先将各个点的坐标求出存入,由pick定理知:
面积 = 内部格点数目+边上格点数目/2-1;
每条边边格点数目 = gcd(x2-x1,y2-y1);
内部格点数目 = 面积+1-边界格点数目/2;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct node
{
int x;
int y;
} point[];
double area_polygon(int n)//求多边形面积
{
double s1=,s2=;
int i;
for (i=; i<=n; i++)
{
s1+=point[i%n].y*point[i-].x;
s2+=point[i%n].y*point[(i+)%n].x;
}
return fabs(s1-s2)/;
}
int main()
{
int t,o = ;
scanf("%d",&t);
while(t--)
{
++o;
int n,dx,dy,cnt = ;
point[].x = ;
point[].y = ;
scanf("%d",&n);
for (int i = ; i <= n; i++)
{
scanf("%d %d",&dx,&dy);
point[i].x = point[i-].x+dx;//存入各点坐标(前一个坐标加偏移量)
point[i].y = point[i-].y+dy;
cnt += __gcd(abs(point[i].x-point[i-].x),abs(point[i].y-point[i-].y));
//cnt代表边上的点
}
double A = area_polygon(n);
int inpoint = A+-cnt/;//pick定理(面积 = 内部格点数目+边上格点数目-1)
printf("Scenario #%d:\n",o);
printf("%d %d %.1f\n\n",inpoint,cnt,A);
}
return ;
}
Area(pick定理)的更多相关文章
- Area(Pick定理POJ1256)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5429 Accepted: 2436 Description ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
- poj 1265 Area(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- POJ 1265 Area (Pick定理 & 多边形面积)
题目链接:POJ 1265 Problem Description Being well known for its highly innovative products, Merck would d ...
- [poj 1265]Area[Pick定理][三角剖分]
题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...
- poj 1265 Area( pick 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- poj 1265 Area(Pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5666 Accepted: 2533 Description ...
- POJ 1265 Area POJ 2954 Triangle Pick定理
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5227 Accepted: 2342 Description ...
随机推荐
- UIResponder详解
UIResponder Class Reference Managing the Responder Chain 1.- (UIResponder *)nextResponder 返回接收者的下一个相 ...
- js 时间 Fri Dec 12 2014 08:00:00 GMT+0800
第一种var d = new Date('Fri Dec 12 2014 08:00:00 GMT+0800'); ) + '-' + d.getDate() + ' ' + d.getHours() ...
- Django - 创建多对多及增加示例
创建多对多: 方式一: 自定义关系表 备注:自定义表Host.Application,通过自定义表,将表Host和Application进行关联(通过外键方式工): 执行语句:python manag ...
- Linux自动化之Cobbler补鞋匠安装
cobbler介绍: 快速网络安装linux操作系统的服务,支持众多的Linux发行版:Red Hat. Fedora.CentOS.Debian.Ubuntu和SuSE,也可以支持网络安装w ...
- JavaScript学习笔记之对象
目录 1.自定义对象 2.Array 3.Boolean 4.Date 5.Math 6.Number 7.String 8.RegExp 9.Function 10.Event 在 JavaScri ...
- Vue ui 大法哪家强?
Element iView Vuex Mint UI Vant cube-ui,对比六大 vue ui 组件库,选中最适合的那个. Element(pc) 介绍 & 版本 饿了么前端团队开发的 ...
- textarea 提交到数据库的内容,输出到 html 中显示正常的格式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- SVG格式图片转成HTML中SVG的Path路径
AI图标制作完成之后,保存的svg文件包含许多AI的信息,如果要在HTML中使用,我们需要在svg文件中提取/修改信息,重新保存. 1.在AI中已经完成图标,要保存SVG文件,点击“文件(File)” ...
- 创建RpcEnv
感觉这篇文章不错 2.1.2.创建RpcEnv - RpcEndpoint - RpcEndpointRef val systemName = if (isDriver) driverSystem ...
- .Net操作Excel —— NPOI
近期的两个项目都有关于NPOI的功能,经过了一点学习,自己也摸索了一会,感觉还有点意思.现在将部分代码分享一下.一部分是C#代码,一部分是VB.Net的,懒得修改了,基本上都是从项目文件中copy出来 ...