题意:计算多边形面积
注意:要用long long,没注意 wa了一次,,
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
#define LL long long
struct cpoint{
LL x,y;
}o,a,b;
LL x_mult(cpoint a,cpoint b,cpoint c){
return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
LL dx[]={-1,-1,-1,0,1,1,1,0};
LL dy[]={-1,0,1,1,1,0,-1,-1};
int mp[]={-1,4,5,6,3,-1,7,2,1,0};
int main()
{
freopen("in.txt","r",stdin);
int cas;
LL area;
char ch[1000009];
scanf("%d",&cas);
while(cas--)
{
scanf("%s",ch);
int len = strlen(ch);
area = 0;
o.x=0,o.y=0,a.x=0,a.y=0,b.x=0,b.y=0;len--;
for(int i=0;i<len;i++)
{
a=b;
b.x+=dx[mp[ch[i]-'0']];
b.y+=dy[mp[ch[i]-'0']];
area+=x_mult(a,b,o);
}
if(area<0) area = -area;
if(area&1LL)
printf("%lld.5\n",area>>1LL);
else
printf("%lld\n",area>>1LL);
}
return 0;
}