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定理)的更多相关文章

  1. Area(Pick定理POJ1256)

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5429   Accepted: 2436 Description ...

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

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

  3. POJ1265——Area(Pick定理+多边形面积)

    Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...

  4. poj 1265 Area(pick定理)

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

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

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

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

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

  7. poj 1265 Area( pick 定理 )

    题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标   变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...

  8. poj 1265 Area(Pick定理)

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

  9. POJ 1265 Area POJ 2954 Triangle Pick定理

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

随机推荐

  1. Unity如何播放带有alpha 通道的视频

    问题: 当使用Video Player播放带有alpha 通道的视频时带有黑色背景 解决方式: 使用文件格式为WEBM的视频,对视频文件进行的修改 在RawImage中,将New Render Tex ...

  2. cv的期刊和会议

    http://blog.csdn.net/tmylzq187/article/details/51111421

  3. EasyUI, Dialog 在框架页(ifrmae)的Top页面弹出时,拖拽Dialog边缘(以改变窗口大小),UI界面被卡死的解决办法

    将Dialog的modal属性设置为true,可以解决卡死的问题(但会给用户使用体验带来影响) var par = { title: This.title, width: This.width, he ...

  4. 直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章

    直流电机PWM调速系统中控制电压非线性研究_控制元件_工业自动化控制_文章_e-works数字化企业网 http://articles.e-works.net.cn/Component/Article ...

  5. Mac下对Android apk反编译

    在Mac上进行反编译apk,需要三个工具,分别为(附下载地址): apktool,下载Mac版 作用:资源文件获取,能够提取出图片文件和布局文件进行使用查看 dex2jar,下载最新的即可,目前是2. ...

  6. 快速搭建vue2.0+boostrap项目

    一.Vue CLI初始化Vue项目 全局安装vue cli npm install --global vue-cli 创建一个基于 webpack 模板的新项目 vue init webpack my ...

  7. PAT 1103 Integer Factorization

    The K-P factorization of a positive integer N is to write N as the sum of the P-th power of K positi ...

  8. 该页必须使用安全性较高的Web 浏览器查看

    当用https访问某个网站时,IE提醒“该页必须使用安全性较高的Web 浏览器查看” 您要访问的资源使用了128位版本的“安全套接层(SSL)” 安全保护.要查看该资源,您需要使用支持该版本的SSL浏 ...

  9. App架构设计经验谈:接口”安全机制”的设计

    [原文地址 点击打开链接] 原创文章,转载请注明:转载自Keegan小钢 并标明原文链接:http://keeganlee.me/post/architecture/20160107 微信订阅号:ke ...

  10. 我要抓狂了。。又回到了几天不能A一道题的时候

    poj1556我不做了.你做做把...我已经要game over了