poj 1654 Area (多边形求面积)
2014-08-10 15:26
453 查看
链接:http://poj.org/problem?id=1654
Area
Description
You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.
For example, this is a legal polygon to be computed and its area is 2.5:
View Code
Area
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 14952 | Accepted: 4189 |
You are going to compute the area of a special kind of polygon. One vertex of the polygon is the origin of the orthogonal coordinate system. From this vertex, you may go step by step to the following vertexes of the polygon until back to the initial vertex. For each step you may go North, West, South or East with step length of 1 unit, or go Northwest, Northeast, Southwest or Southeast with step length of square root of 2.
For example, this is a legal polygon to be computed and its area is 2.5:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <algorithm> #include <math.h> #define MAXX 1000002 #define eps 1e-6 typedef struct { double x; double y; } point; double crossProduct(point a,point b,point c) { return (c.x-a.x)*(b.y-a.y)-(c.y-a.y)*(b.x-a.x); } bool dy(double x,double y) { return x>y+eps; } bool xy(double x,double y) { return x<y-eps; } bool dd(double x,double y) { return fabs(x-y)<eps; } int main() { int n,m,i,j,x,y; scanf("%d",&n); char str[MAXX]; int move[10][2]= {{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}}; for(i=0; i<n; i++) { scanf("%s",str); int len=strlen(str); int x1=0,y1=0,x2,y2; long long ans=0; for(j=0; j<len-1; j++) { x2=x1+move[str[j]-'0'][0]; y2=y1+move[str[j]-'0'][1]; ans+=((x1*y2)-(x2*y1)); x1=x2; y1=y2; } ans = ans > 0 ? ans : (-1)*ans; if(ans == 0) printf("0\n"); else if(ans % 2 == 0) printf("%lld\n",ans/2); else if(ans % 2 != 0) printf("%lld.5\n",ans/2); } return 0; }
View Code
相关文章推荐
- poj 1654 Area 多边形面积
- poj 1654 area 简单多边形面积(简单题)
- POJ 1654 Area [多边形面积]
- POJ 1654 Area [多边形面积]
- POJ 1654 Area (求多边形面积)
- POJ 1654 Area(叉积计算多边形面积)
- poj 1654 Area(求多边形面积)
- POJ 1654 Area(多边形面积)
- poj 1654 Area(求多边形面积 && 处理误差)
- POJ 1654 Area 多边形面积
- [POJ1654]Area(计算几何-多边形的面积)
- poj1654—Area(计算几何求多边形面积)
- POJ 1654 Area(任意多边形面积)
- POJ 1654 Area 多边形面积
- POJ 1654 Area(多边形面积)
- POJ 1654 || Area(求多边形面积
- POJ 1654 Area (多边形面积)
- POJ1654 Area(多边形面积,叉积求三角形面积)
- POJ-1654Area(求多边形面积)
- Area(poj1654多边形面积)