题目:http://poj.org/problem?id=1265

题意 : 给你一个点阵,上边有很多点连成的多边形,让你求多边形内部的点和边界上的点以及多边形的面积,要注意他每次给出的点并不是点的横纵坐标,而是相对于上一个点的横纵坐标离开的距离dx,dy,所以你还要求一下每个点的坐标,然后再进行别的操作就可以了

题目解析:

这个题用了很多知识点:

1、以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其中,dxdy分别为线段横向占的点数和纵向占的点数。如果dx或dy为0,则覆盖的点数为dy或dx。
2、Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1。
3、任意一个多边形的面积等于按顺序求相邻两个点与原点组成的向量的叉积之和/2。

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
#define inf 0x3f3f3f3f
#define eps 1e-9
typedef long long ll;
using namespace std;
struct point
{
int x,y;
} q[];
int n;
ll num,In;
double S;
int gcd(int A,int B)
{
return B==?A:gcd(B,A%B);
}
int Mult(point A,point B)
{
return A.x*B.y-B.x*A.y;
}
int main()
{
int T,xx,yy,sx,sy,dx,dy,K=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
sx=sy=;
S=;
num=;
for(int i=; i<=n; i++)
{
scanf("%d%d",&xx,&yy);
sx+=xx;
sy+=yy;
q[i].x=sx;
q[i].y=sy;
}
q[].x=q[n].x;
q[].y=q[n].y;
for(int i=; i<n; i++)
{
S+=Mult(q[i],q[i+]);
dx=abs(q[i].x-q[i+].x);
dy=abs(q[i].y-q[i+].y);
num+=gcd(max(dx,dy),min(dx,dy));
}
S=fabs(S/);//不确定S是否为正数
In=int(S)+-num/;
printf("Scenario #%d:\n",++K);
printf("%I64d %I64d %.1f\n\n",In,num,S);
}
return ;
}

代码:

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <queue>
#define inf 0x3f3f3f3f
#define eps 1e-9
typedef long long ll;
using namespace std;
struct point
{
int x,y;
} q[];
int n;
ll num,In;
double S;
int gcd(int A,int B)
{
return B==?A:gcd(B,A%B);
}
int Mult(point A,point B)
{
return A.x*B.y-B.x*A.y;
}
int main()
{
int T,xx,yy,dx,dy,K=;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
q[].x=;
q[].y=;
S=;
num=;
for(int i=; i<=n; i++)
{
scanf("%d%d",&xx,&yy);
q[i].x=q[i-].x+xx;
q[i].y=q[i-].y+yy;
}
for(int i=; i<n; i++)
{
S+=Mult(q[i],q[i+]);
dx=abs(q[i].x-q[i+].x);
dy=abs(q[i].y-q[i+].y);
num+=gcd(max(dx,dy),min(dx,dy));
}
S=fabs(S/);//不确定S是否为正数
In=int(S)+-num/;
printf("Scenario #%d:\n",++K);
printf("%I64d %I64d %.1f\n\n",In,num,S);
}
return ;
}

POJ1265:Area(多边形面积公式+pick公式) 好题的更多相关文章

  1. POJ1265 Area 多边形内格点数 Pick公式

    POJ1265给定一个多边形 计算边上的格点 内部的格点 以及多边形的面积 利用Pick公式  面积=内部格点数+边上格点数/2-1 将多边形分割为三角形容易证得上述公式 计算面积用叉积,计算边上格点 ...

  2. poj 1654 Area 多边形面积

    /* poj 1654 Area 多边形面积 题目意思很简单,但是1000000的point开不了 */ #include<stdio.h> #include<math.h> ...

  3. POJ 1654 Area 多边形面积 G++会WA

    #include<stdio.h> #include<algorithm> #include <cstring> using namespace std; type ...

  4. POJ 1265 Area POJ 2954 Triangle Pick定理

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

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

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

  6. Area - POJ 1265(pick定理求格点数+求多边形面积)

    题目大意:以原点为起点然后每次增加一个x,y的值,求出来最后在多边形边上的点有多少个,内部的点有多少个,多边形的面积是多少. 分析: 1.以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其 ...

  7. poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】

    题目:http://poj.org/problem?id=1265 Sample Input 2 4 1 0 0 1 -1 0 0 -1 7 5 0 1 3 -2 2 -1 0 0 -3 -3 1 0 ...

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

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

  9. poj 1654:Area 区域 ---- 叉积(求多边形面积)

    Area   Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19398   Accepted: 5311 利用叉积求多边形面 ...

随机推荐

  1. JS 拖动原理

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. HBase源码学习系列

    转自:http://www.cnblogs.com/cenyuhai/tag/hbase%E6%BA%90%E7%A0%81%E7%B3%BB%E5%88%97/ (mark) hbase源码系列(十 ...

  3. commit命令

    git commit -m "测试提交"

  4. sdut 2153:Clockwise(第一届山东省省赛原题,计算几何+DP)

    Clockwise Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Saya have a long necklace with ...

  5. 【转】Native Thread for Win32 B-Threads Synchronization(通俗易懂,非常好)

    http://www.bogotobogo.com/cplusplus/multithreading_win32B.php   Synchronization Between Threads In t ...

  6. P2483 [SDOI2010]魔法猪学院

    P2483 [SDOI2010]魔法猪学院 摘要 --> 题目描述 iPig在假期来到了传说中的魔法猪学院,开始为期两个月的魔法猪训练.经过了一周理论知识和一周基本魔法的学习之后,iPig对猪世 ...

  7. js的等于号==的判断

    var str=0; str == "" 将返回true:

  8. LeetCode 笔记系列15 Set Matrix Zeroes [稍微有一点hack]

    题目:Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Fol ...

  9. 元素隐藏 css

    参考:http://www.zhangxinxu.com/wordpress/2011/03/css-%E7%9B%B8%E5%AF%B9%E7%BB%9D%E5%AF%B9relativeabsol ...

  10. 160617、使用espeak将文字转语音(TTS)

    http://www.eguidedog.net/cn/WebSpeech_cn.php 简单使用例子: <html> <head> <meta http-equiv=& ...