7 8 9
4 5 6
1 2 3
如上键位,从原点开始,按数字几就是往哪个方向走,5停止
求从原点开始,走过这些的路径围成的多边形的面积,用叉积来算就好了,以原点为起点,很easy
不过爆int了没弄清楚范围,wa了几发!!!!!
还有就是哪个输出,一定要弄成这样,我试了别的都wa。。。
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>
using namespace std;
string str;
int maps[10][2]={0,0,-1,-1,0,-1,1,-1,-1,0,0,0,1,0,-1,1,0,1,1,1};
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
cin>>str;
int len = str.length();
if( len<=2 )
puts("0");
else{
long long x,y,xx,yy;
x = y = 0;
long long ans = 0.0;
for( int i = 0;i < len-1; ++i){
xx = x+maps[str[i]-'0'][0];
yy = y+maps[str[i]-'0'][1];
ans += x*yy - y*xx;
x = xx;
y = yy;
}
if(ans<0) ans=(-1)*ans;
if(ans%2==0)
printf("%lld\n",ans/2);
else printf("%lld.5\n",ans/2);
}
}
return 0;
}