#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
struct Point
{
double x,y;
Point(){}
Point(double _x,double _y)
{
x = _x;y = _y;
}
//向量
Point operator -(const Point &b)const
{
return Point(x - b.x,y - b.y);
}
//叉积
double operator ^(const Point &b)const
{
return x*b.y - y*b.x;
}
//点积
double operator *(const Point &b)const
{
return x*b.x + y*b.y;
}
void input()
{
scanf("%lf%lf",&x,&y);
}
};
const int maxn = 1100000;
char cmd[maxn];
int main()
{
int t;
scanf("%d", &t);
while (t--) {
scanf("%s", cmd);
int len = strlen(cmd);
Point cur(0,0), next;
double ans = 0;
for (int i = 0; i < len; i++) {
if (cmd[i] == '8') {
next.x = cur.x;
next.y = cur.y + 1;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '2') {
next.x = cur.x;
next.y = cur.y - 1;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '6') {
next.x = cur.x + 1;
next.y = cur.y;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '4') {
next.x = cur.x - 1;
next.y = cur.y;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '1') {
next.x = cur.x - 1;
next.y = cur.y - 1;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '3') {
next.x = cur.x + 1;
next.y = cur.y - 1;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '7') {
next.x = cur.x - 1;
next.y = cur.y + 1;
ans += cur ^ next;
cur = next;
} else if (cmd[i] == '9') {
next.x = cur.x + 1;
next.y = cur.y + 1;
ans += cur ^ next;
cur = next;
}
}
ans = fabs(ans) / 2.0;
if (fabs(floor(ans) - ans) < 1e-8)
printf("%.0lf\n", ans);
else
printf("%.1lf\n", ans);
}
return 0;
}
POJ 1654 Area (有向面积求多边形面积)
最新推荐文章于 2019-10-28 15:52:03 发布