PS: 叉积求面积, 注意保存点集会超内存。
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <algorithm> #include <vector> #include <cmath> using namespace std; const int maxn = 1000010; char str[maxn]; struct point { double x, y; point(double x = 0, double y = 0) :x(x),y(y) {} }; vector<point> v; point operator - (point A, point B) { return point(A.x-B.x, A.y-B.y); } point operator + (point A, point B) { return point(A.x+B.x, A.y+B.y); } double Cross(point A, point B) { return A.x*B.y - A.y*B.x; } long long work() { int len = strlen(str); if(len<=2) return 0; point p(0,0); point q(0,0); long long res = 0; for(int i = 0; i <= len-2; i++) { if(str[i]=='8') p = p + point(-1, 0); else if(str[i]=='2') p = p + point(1,0); else if(str[i]=='4') p = p + point(0,-1); else if(str[i]=='6') p = p + point(0, 1); else if(str[i]=='1') p = p + point(1, -1); else if(str[i]=='3') p = p + point(1, 1); else if(str[i]=='7') p = p + point(-1, -1); else if(str[i]=='9') p = p + point(-1, 1); res += Cross(q, p); q = p; } return res; } int main() { int T; scanf("%d", &T); getchar(); while(T--) { gets(str); long long res = work(); res = fabs(res); if(res%2) { printf("%I64d", res/2); printf(".5\n"); } else printf("%I64d\n", res/2); } return 0; }