题意:求多边形的面积.
就输出处理一下就好了.
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int eps = 1e-8;
const int INF = 1e20;
const int pi = acos (-1.0);
int dcmp (int x) {
if (fabs (x) < eps) return 0;
return (x < 0 ? -1 : 1);
}
inline int sqr (int x) {return x*x;}
struct Point {
int x, y;
Point (int _x = 0, int _y = 0):x(_x), y(_y) {}
void input () {scanf ("%lf%lf", &x, &y);}
void output () {printf ("%.2f %.2f\n", x, y);}
bool operator == (const Point &b) const {
return (dcmp (x-b.x) == 0 && dcmp (y-b.y) == 0);
}
bool operator < (const Point &b) const {
return (dcmp (x-b.x) == 0 ? dcmp (y-b.y) < 0 : x < b.x);
}
Point operator + (const Point &b) const {
return Point (x+b.x, y+b.y);
}
Point operator - (const Point &b) const {
return Point (x-b.x, y-b.y);
}
Point operator * (int a) {
return Point (x*a, y*a);
}
Point operator / (int a) {
return Point (x/a, y/a);
}
int len2 () {
return sqr (x) + sqr (y);
}
int len () {
return sqrt (len2 ());
}
};
int cross (Point a, Point b) {
return 1LL*a.x*b.y-1LL*a.y*b.x;
}
double polygon_area (Point *p, int n) {
double area = 0;
for (int i = 1; i < n-1; i++) {
area += cross (p[i]-p[0], p[i+1]-p[0]);
}
return area/2;
}
#define maxn 1000005
Point p[maxn];
int n;
char s[maxn];
int main () {
int t;
cin >> t;
while (t--) {
scanf ("%s", s);
n = strlen (s); n--;
if (n == 0 || n == 2) {
printf ("0\n");
continue;
}
n--;
int len = 0;
p[len++] = Point (0, 0);
for (int i = 0; i < n; i++) {
if (s[i] == '8') p[len++] = p[len-1]+Point (0, 1);
if (s[i] == '7') p[len++] = p[len-1]+Point (-1, 1);
if (s[i] == '9') p[len++] = p[len-1]+Point (1, 1);
if (s[i] == '4') p[len++] = p[len-1]+Point (-1, 0);
if (s[i] == '6') p[len++] = p[len-1]+Point (1, 0);
if (s[i] == '1') p[len++] = p[len-1]+Point (-1, -1);
if (s[i] == '2') p[len++] = p[len-1]+Point (0, -1);
if (s[i] == '3') p[len++] = p[len-1]+Point (1, -1);
}
double ans = fabs (polygon_area (p, len))*2+eps;
long long res = (long long)ans;
printf ("%lld%s\n", res/2, (res&1 ? ".5" : ""));
}
return 0;
}