POJ 1654
不知 是怎么看出的精度不够,吸经验吧。
#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;
}

浙公网安备 33010602011771号