利用向量积=ab*ac*sin(ab,ac)=2*S三角形ABC
按逆时针依次计算多边形相邻两个顶点和原点构成向量的叉积,及把多边形分成若干个三角形,累加即可
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N=2e6+20;
string s;
double cross(double x,double y,double a,double b)
{
return x*b-a*y;
}
int main()
{
int t;
cin>>t;
while(t--)
{
ll ans=0;
cin>>s;
double x,y,a=0,b=0;
for(int i=0;s[i];i++)
{
x=a,y=b;
if(s[i]=='5')
break;
if(s[i]=='8')
y++;
if(s[i]=='2')
y--;
if(s[i]=='6')
x++;
if(s[i]=='4')
x--;
if(s[i]=='9')
x++,y++;
if(s[i]=='7')
x--,y++;
if(s[i]=='3')
x++,y--;
if(s[i]=='1')
x--,y--;
if(i>0)
ans+=cross(x,y,a,b);
a=x,b=y;//前驱
}
if(ans<0)
ans=-ans;
cout<<ans/2;
if(ans%2)
printf(".5");
cout<<endl;
}
return 0;
}