POJ 1265 Area
来源:互联网 发布:pc视频剪辑软件 编辑:程序博客网 时间:2024/05/22 08:06
题目大意:
给一个平面上的简单多边形,求边上的点,多边形内的点,多边形面积。
解题思路:
这个题用了很多知识点:
1、以格子点为顶点的线段,覆盖的点的个数为GCD(dx,dy),其中,dxdy分别为线段横向占的点数和纵向占的点数。如果dx或dy为0,则覆盖的点数为dy或dx。
2、Pick公式:平面上以格子点为顶点的简单多边形的面积=边上的点数/2+内部的点数+1。
3、任意一个多边形的面积等于按顺序求相邻两个点与原点组成的向量的叉积之和。
只要知道了这些,代码很好写,注意细节就行了。
下面是代码:
#include <stdio.h>struct node{ int x,y;} point[110];int n;int gcd(int a,int b){ return b?gcd(b,a%b):a;}int Area(node a,node b){ return a.x*b.y-a.y*b.x;}int main(){ int T,case1=0; scanf("%d",&T); while(T--) { case1++; int a=0,p=0,dx,dy,i; scanf("%d",&n); point[0].x=0; point[0].y=0; for(i=1; i<=n; i++) { scanf("%d%d",&point[i].x,&point[i].y); dx=point[i].x; if(dx<0)dx=-dx; dy=point[i].y; if(dy<0)dy=-dy; p+=gcd(dx,dy); point[i].x+=point[i-1].x; point[i].y+=point[i-1].y; a+=Area(point[i],point[i-1]); } if(a<0)a=-a; printf("Scenario #%d:\n",case1); printf("%d %d %.1f\n\n",(a-p+2)/2,p,0.5*a); } return 0;}
0 0
- Poj 1265 Area
- poj 1265 Area
- POJ 1265 Area
- poj 1265 Area
- POJ 1265 Area
- POJ 1265 Area
- POJ 1265 Area
- POJ 1265 Area
- poj 1265 Area
- POJ 1265:Area
- POJ 1265 Area
- POJ 1265 Area
- poj 1265 Area
- poj-1265 Area
- poj 1265 Area
- POJ 1265 Area
- POJ 1265 Area
- poj 1265 Area
- 黑马程序员--泛型
- Oracle 字符集的查看和修改
- 没有为扩展名“.html”注册的生成提供程序
- JPBM4.4基础及数据库说明
- lua中table活用
- POJ 1265 Area
- 在PHP中利用wsdl创建标准webservice
- Myeclipse10激活
- [the summarization of algorithm]Heap and Heapsort
- Hercules 3.09 的安装与配置
- UVALive - 4254 Processor
- java(2014)实现对mysql数据库分页的代码
- 时间限制: 1000ms 内存限制: 256MB
- Windows 7多核评测:究竟快了多少?