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 ...
随机推荐
- TCP:三次握手,URG、ACK、PSH、RST、SYN、FIN 含义
http://blog.csdn.net/wudiyi815/article/details/8505726 TCP:SYN ACK FIN RST PSH URG简析 三次握手Three-way ...
- 太坑了,mybatis注解一对多,id没了
@Select("SELECT *, id nodes FROM QUESTION_PO WHERE ID=#{id}") @Results({ @Result(property ...
- Python random模块&string模块 day3
一.random模块的使用: Python中的random模块用于生成随机数.下面介绍一下random模块中最常用的几个函数. 1.常用函数: (1)random.random() 用于生成一个0到1 ...
- 网络编程_socketserver
一.socketserver 网络编程 1.socketserver支持多用户并发处理:2.socketserver是对socket的再封装;处理步骤:1.创建一个socketserver类2.继承B ...
- [forward]警惕UNIX下的LD_PRELOAD环境变量
From: https://blog.csdn.net/haoel/article/details/1602108 警惕UNIX下的LD_PRELOAD环境变量 前言 也许这个话题并不新鲜,因为LD_ ...
- 本地文件与服务器文件同步shell脚本
为何创建此脚本是因为方便项目的布署,不需要手动地去同步不同的项目,而只需要简单的执行shell脚本,输入项目名就能发布到服器上. 1.shell文件代码 #!/bin/sh read -t 30 -p ...
- 【1657: [蓝桥杯][算法训练VIP]】统计单词个数
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设dp[i][j]表示前i个字符分成j个部分的最多匹配单词个数. 则dp[i][j] = dp[prei][j-1] + get_num(pr ...
- ansible common modules
##Some common modules[cloud modules] [clustering modules] [command modules]command - executes a comm ...
- BNUOJ 3958 MAX Average Problem
MAX Average Problem Time Limit: 3000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Jav ...
- hdu_1863_畅通工程_201403122000
畅通工程 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...