码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 1654

时间:2014-07-29 11:05:46      阅读:214      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   div   ar   amp   ios   

不知 是怎么看出的精度不够,吸经验吧。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

char str[1000050];
int dir[10][2]={
{0,0},{-1,-1},{0,-1},{1,-1},{-1,0},{0,0},{1,0},{-1,1},{0,1},{1,1}
};

struct point{
	__int64 x,y;
};

__int64 cross(point a,point b){
	return a.x*b.y-b.x*a.y;
}

int main(){
	int t; __int64 xt,yt; __int64 ans;
	scanf("%d",&t);
	getchar();
	while(t--){
		scanf("%s",str);
		xt=yt=0; ans=0; point pre,now; pre.x=pre.y=0;
		for(int i=0;str[i]!=‘5‘;i++){
			xt+=dir[str[i]-‘0‘][0];
			yt+=dir[str[i]-‘0‘][1];
			now.x=xt; now.y=yt;
			ans+=cross(pre,now);
			pre=now;
		}
		if(xt==0&&yt==0){
			if(ans<0) ans=-ans;
			if(ans%2==0)
				printf("%I64d\n",ans/2);
			else printf("%I64d.5\n",ans/2);
		}
		else printf("0\n");
	}
	return 0;
}

  

POJ 1654,布布扣,bubuko.com

POJ 1654

标签:blog   os   io   for   div   ar   amp   ios   

原文地址:http://www.cnblogs.com/jie-dcai/p/3873964.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!