poj 1654 Area
#include<iostream> //多边形面积
#include<string>
using namespace std;
struct point
{
int x,y;
}p[1000010];
int move[10][2]={{},{-1,-1},{0,-1},{1,-1},{-1,0},{},{1,0},{-1,1},{0,1},{1,1}};
int main()
{
int cases;
string str;
cin>>cases;
while(cases--)
{
cin>>str;
int n=str.size()-1;
if(n<3)
{
printf("0\n");
continue;
}
p[0].x=p[0].y=0;
for(int i=0;i<n;++i)
{
p[i+1].x=p[i].x+move[str[i]-'0'][0];
p[i+1].y=p[i].y+move[str[i]-'0'][1];
}
__int64 area=0; //超int范围
for(int i=0;i<n;++i)
area+=p[i].x*p[i+1].y-p[i].y*p[i+1].x;
area+=p[n].x*p[0].y-p[n].y*p[0].x;
if(area<0)
area=-area;
if(area%2==0) //答案要么是整数,要么是整数+0.5.不能用double存储,精度会不够.
printf("%I64d\n",area/2);
else
printf("%I64d.5\n",area/2);
}
return 0;
}