pku 1654 Area 叉积求多边形面积
2012-05-22 19:08
381 查看
http://poj.org/problem?id=1654Area
给定起点(0,0)然后给出1 - 4 | 6 - 9 表示走的方向,输入数据保证能够回到原点。很裸的叉积求多边形面积。这里精度控制很坑爹,只要出现小数就取整数+0.5,double不能控制,所以用long long或者__int64来控制。
给定起点(0,0)然后给出1 - 4 | 6 - 9 表示走的方向,输入数据保证能够回到原点。很裸的叉积求多边形面积。这里精度控制很坑爹,只要出现小数就取整数+0.5,double不能控制,所以用long long或者__int64来控制。
#include <cstdio> #include <cstring> #include <iostream> #define maxn 1000010 struct point { int x,y; }p[maxn]; char str[maxn]; int dir[10][2] = {{-1,-1},{0,-1},{1,-1},{-1,0},{1,0},{-1,1},{0,1},{1,1}}; double det(double x1,double y1,double x2,double y2) { return x1*y2 - x2*y1; } int main() { int t,i; __int64 ans; scanf("%d",&t); while (t--) { i = 1; double tx = 0,ty = 0; ans = 0; scanf("%s",str); int len = strlen(str) - 1; for (i = 0; i < len; ++i) { //printf("%c",str[i]); int pos = str[i] - '0'; //注意我们初始化的方向是0-8,在这里调整 if (pos > 5) pos -= 2; else pos--; double xx = tx + dir[pos][0]; double yy = ty + dir[pos][1]; //printf("%lf %lf %lf %lf\n",tx,ty,xx,yy); ans += (__int64)det(xx,yy,tx,ty); tx = xx; ty = yy; } if (ans < 0) ans = -ans; if (ans%2 != 0) printf("%I64d.5\n",ans/2); else printf("%I64d\n",ans/2); } return 0; }
相关文章推荐
- POJ 1654 Area(叉积计算多边形面积)
- POJ1654 Area(多边形面积,叉积求三角形面积)
- poj 1654 Area(叉积求多边形面积)
- pku 1654 Area(向量叉积算面积)
- (计算几何POJ step 8.1.1.2)POJ 1654 Area(使用叉积来计算多边形面积)
- poj 1654:Area 区域 ---- 叉积(求多边形面积)
- poj 1654 Area 多边形面积
- pku 2954 Triangle && pku 1265 Area Pick定理的应用 + 叉积求多边形面积
- POJ 1654 Area (叉积求三角形面积)
- POJ 1654 Area 多边形面积 G++会WA
- poj 1654 area 简单多边形面积(简单题)
- POJ 1654 Area [多边形面积]
- poj 1654 Area(求多边形面积)
- poj 1265 Area【计算几何:叉积计算多边形面积+pick定理计算多边形内点数+计算多边形边上点数】
- poj 1654 Area 多边形面积
- POJ 1265-Area(多边形面积、边点、内点-pick定理、叉积)
- POJ 1654 Area 多边形面积
- Area - POJ 1654(求多边形面积)
- poj 1654 Area(多边形面积)
- POJ 1654 Area [多边形面积]