#include<stdio.h> #include<algorithm> #include <cstring> using namespace std; typedef long long ll; const int MAXN = 1000008; char s[MAXN]; int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1}; int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1}; int main() { // freopen("in.txt","r",stdin); int T; scanf("%d", &T); while(T--) { scanf("%s", s); int len = strlen(s); int x, y, nx, ny; x = y = 0; ll ans = 0; for(int i=0; i<len; i++) { nx = x + dx[s[i]-'1']; ny = y + dy[s[i]-'1']; ans += x*ny - y*nx; x = nx; y = ny; } if(ans < 0) ans = -ans; printf("%I64d", ans / 2); if(ans % 2 == 1) printf(".5"); puts(""); } return 0; }
本文介绍了一个使用C++实现的计算平面折线路径所围成的多边形面积的方法。通过输入由9个方向字符组成的字符串来确定折线路径,进而计算出该路径所围成的多边形面积,并考虑了面积的正负问题以确保结果的准确性。
317

被折叠的 条评论
为什么被折叠?



