poj1265Area(pick定理)
Pick定理是说,在一个平面直角坐标系内,如果一个多边形的顶点全都在格点上,那么这个图形的面积恰好就等于边界上经过的格点数的一半加上内部所含格点数再减一。
题意不好懂,给出的x,y并不是坐标而是向x轴方向y轴方向移动的距离。
#include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<cmath>
#include<queue>
#include<set>
using namespace std;
#define N 110
#define LL long long
#define INF 0xfffffff
const double eps = 1e-;
const double pi = acos(-1.0);
const double inf = ~0u>>;
struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y) {}
}p[N];
typedef Point pointt;
pointt operator + (Point a,Point b)
{
return Point(a.x+b.x,a.y+b.y);
}
pointt operator - (Point a,Point b)
{
return Point(a.x-b.x,a.y-b.y);
}
int dcmp(double x)
{
if(fabs(x)<eps) return ;
else return x<?-:;
}
double cross(Point a,Point b)
{
return a.x*b.y-a.y*b.x;
}
double Polyarea(int n)
{
double area = ;
for(int i = ; i < n- ; i++)
area+=cross(p[i]-p[],p[i+]-p[]);
return area/;
}
int main()
{
int t,i,n,kk=;
cin>>t;
while(t--)
{
scanf("%d",&n);
int num = ;
p[].x = ,p[].y = ;
for(i = ; i <= n ;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
p[i].x+=p[i-].x;
p[i].y+=p[i-].y;
}
p[n+] = ;
for(i = ; i <= n ;i++)
{
Point pp = p[i]-p[i+];
pp.x = fabs(pp.x),pp.y = fabs(pp.y);
if(dcmp(pp.x)==||dcmp(pp.y)==)
num+=pp.x+pp.y;
else
num+=__gcd((int)pp.x,(int)pp.y);
}
double s = Polyarea(n);
printf("Scenario #%d:\n",++kk);
printf("%d %d %.1f\n",(int)s+-num/,num,s);
puts("");
}
return ;
}
poj1265Area(pick定理)的更多相关文章
- HDU 3775 Chain Code ——(Pick定理)
Pick定理运用在整点围城的面积,有以下公式:S围 = S内(线内部的整点个数)+ S线(线上整点的个数)/2 - 1.在这题上,我们可以用叉乘计算S围,题意要求的答案应该是S内+S线.那么我们进行推 ...
- 【POJ】2954 Triangle(pick定理)
http://poj.org/problem?id=2954 表示我交了20+次... 为什么呢?因为多组数据我是这样判断的:da=sum{a[i].x+a[i].y},然后!da就表示没有数据了QA ...
- UVa 10088 - Trees on My Island (pick定理)
样例: 输入:123 16 39 28 49 69 98 96 55 84 43 51 3121000 10002000 10004000 20006000 10008000 30008000 800 ...
- Area(Pick定理POJ1256)
Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5429 Accepted: 2436 Description ...
- poj 2954 Triangle(Pick定理)
链接:http://poj.org/problem?id=2954 Triangle Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- poj 1265 Area (Pick定理+求面积)
链接:http://poj.org/problem?id=1265 Area Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- pick定理:面积=内部整数点数+边上整数点数/2-1
//pick定理:面积=内部整数点数+边上整数点数/2-1 // POJ 2954 #include <iostream> #include <cstdio> #include ...
- UVa 10088 (Pick定理) Trees on My Island
这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...
- POJ1265——Area(Pick定理+多边形面积)
Area DescriptionBeing well known for its highly innovative products, Merck would definitely be a goo ...
随机推荐
- ecshop后台增加模板页的方法
CShop的动态模板机制是一个非常灵活的系统,管理员可以在后台根据自己的要求调整模板模块的显示位置.本文详细讲解了如何修改ECSHOP内部结构使得用户可以添加自己的模板页从而方便灵活的使用系统自带的模 ...
- Oracle中instr 函数的详解
INSTR (源字符串, 目标字符串, 起始位置, 匹配序号) 在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置.只检索一次,就是说从字符的开始 到字 ...
- [团队项目]后续安排 Github
6.后续安排 第16周 周二晚7点之前将本代码上传到GITHUB. 周三上课时运行你们的系统给我观赏一下. 根据博客,运行演示,github代码情况评定第二个冲刺的分数. 至此,软件工程学期平时分截止 ...
- Linux下怎么运行java程序
在Linux下安装好jdk配置好环境变量后,要回到程序所在的目录下,然后跟在windows一样输入 java (程序名)运行,原理是就好像在Windows的DOS环境下执行java这个命令时必须在 ...
- js去除日期字符串时分秒
var date = "2015-11-11 00:00:00"; var newDate=/\d{4}-\d{1,2}-\d{1,2}/g.exec(date) newDate= ...
- POI 简单合并单元格
public class MergedCells { /** 测试使用的POI版本是3.1 * @param args */ public static void main(String[] args ...
- 2014江西理工大学C语言程序竞赛初级组
坐公交 解法:略 #include<stdio.h> #include<string> #include<iostream> #include<math.h& ...
- centOS6.5安装SUN-jdk7
一.下载SUN-JDK1.7.tar.gz文件他 地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1 ...
- flash视频器播放器代码
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- 年轻的团队Mono玩转Dalvik
真的很羡慕这样的一个团队,年轻充满斗志. 甲骨文和谷歌正就谷歌在Android中使用Java一案展开一场10亿美元的大较量.但是Java并非在Android中建立本地应用的唯一方法.事实上,它甚至不是 ...