[poj 1265]Area[Pick定理][三角剖分]
题意:
给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积.
思路:
面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理.
S = I + E / 2 - 1
I 为内整点数, E为边界整点数, S为面积.
Separate the three numbers by two single blanks.....好吧, 理解成中间空两格PE一次> <
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 105;
int n;
int GCD(int a, int b)
{
return !b?a:GCD(b,a%b);
}
struct point
{
int x,y;
}p[MAXN];
int det(int i, int j)
{
return p[i].x*p[j].y - p[j].x*p[i].y;
}
double CalS()
{
double ret = 0;
for(int i=0;i<n;i++)
{
ret += det(i, i+1);
}
return fabs(ret/2.0);
}
int CalE()
{
int ans = n;
for(int i=0;i<n;i++)
{
int dx = (int)abs((double)(p[i].x - p[i+1].x));
int dy = (int)abs((double)(p[i].y - p[i+1].y));
if(!dx)
{
if(!dy) continue;
ans += dy - 1;
continue;
}
if(!dx)
{
ans += dx - 1;
continue;
}
ans += GCD(dx, dy) - 1;
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
for(int k=1;k<=T;k++)
{
scanf("%d",&n);
p[0].x = p[0].y = 0;
for(int i=1;i<=n;i++)
{
scanf("%d %d",&p[i].x,&p[i].y);
p[i].x += p[i-1].x, p[i].y += p[i-1].y;
}
double S = CalS();
int E = CalE();
printf("Scenario #%d:\n%d %d %.1lf\n\n",k,(int)(S+1.0-E/2.0),E,S);
}
}
[poj 1265]Area[Pick定理][三角剖分]的更多相关文章
- 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(pick定理)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 4373 Accepted: 1983 Description Bein ...
- poj 1265 Area( pick 定理 )
题目:http://poj.org/problem?id=1265 题意:已知机器人行走步数及每一步的坐标 变化量 ,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:1.以 ...
- Area - POJ 1265(pick定理求格点数+求多边形面积)
题目大意:以原点为起点然后每次增加一个x,y的值,求出来最后在多边形边上的点有多少个,内部的点有多少个,多边形的面积是多少. 分析: 1.以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其 ...
- poj 1265 Area 面积+多边形内点数
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5861 Accepted: 2612 Description ...
- 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定理)
题目大意:已知机器人行走步数及每一步的坐标变化量,求机器人所走路径围成的多边形的面积.多边形边上和内部的点的数量. 思路:叉积求面积,pick定理求点. pick定理:面积=内部点数+边上点数/2-1 ...
随机推荐
- 如何在macox下面配置集成ios和android游戏教程
教程截图: 1.准备工作,配置开发环境: 开发环境:mac ox 10.7.3 + xcode4.2 + ndk r7 + eclipse helios 部署环境:中兴v880 root过了 ...
- JavaSE学习总结第06天_Java语言基础2 & 面向对象1
06.01 二维数组概述和格式1的讲解 二维数组概述:二维数组其实就是一个元素为一维数组的数组 格式1:数据类型[][] 变量名 = new 数据类型[m][n]; m表示这个二维数组有多少个一维 ...
- Single Number i and ii
Single Number Given an array of integers, every element appears twice except for one. Find that sing ...
- JS 某一区域内所有CheckBox全选和取消全选(.net)
假设在某个table中的两个td,一个放全选checkbox,一个放所有的checkbox[其他标签类似] eg: <td>人才类别:<asp:CheckBox ID= ...
- DataReader的例子
前: <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DataReader对 ...
- 17.1.1.8?Setting Up Replication with Existing Data设置复制使用存在的数据
17.1.1.8?Setting Up Replication with Existing Data设置复制使用存在的数据 当设置复制使用存在的数据,你需要确定如何最好的从master 得到数据到sl ...
- UITableView 协议中常用的方法
UITableViewDataSource 协议中常用方法 1.设置右边 索引值 - ( NSArray *)sectionIndexTitlesForTableView:( UITableView ...
- Codeforces Round #246 (Div. 2)
题目链接:Codeforces Round #246 (Div. 2) A:直接找满足的人数,然后整除3就是答案 B:开一个vis数组记录每一个衣服的主场和客场出现次数.然后输出的时候主场数量加上反复 ...
- rbd块映射
rbd块映射: root@u18:~# rbd create kvm/test002.img --size root@u18:~# rbd info kvm/test002.img rbd image ...
- 自定义ActionBar背景(分别针对3.0以下和3.0以上的版本)
官方原文:http://developer.android.com/training/basics/actionbar/styling.html 针对3.0以上的版本: <?xml versio ...