Question: starting from a point and eight directions, give the direction of each step and find the area of the polygon formed by the path. However, the question says that we will use the vector cross product to solve the Polygon Area at the beginning and end, and it is not just applicable to convex edges. The concave part is offset by positive and negative.
However, this question does not hate precision.
Double is not allowed, must use an integer, and cannot overflow, with a 64-bit integer, the output area only needs to be divided by 2, so you only need to judge the parity ..... Ah, ah, WA many times not only because of precision, but also the coordinate changes in the eight directions are wrong several times.
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <cmath>
# Include <vector>
# Include <string>
# Include <algorithm>
# Include <queue>
# Define LL _ int64
# Define eps 1e-7
# Define N 2000000
# Define MOD 1000000007.
# Define inf 1 <30
# Define zero (a) (fabs (double) (a) <eps)
Using namespace std;
Struct Point {
Int x, y;
} P [1000005];
Int n;
Int way [9] [2] = {1,-,-, 0, 0, 1,-1,-1 };
LL xmul (Point p0, Point p1, Point p2 ){
Return (LL) (p1.x-Snapshot X) * (p2.y-Snapshot y)-(LL) (p2.x-Snapshot X) * (p1.y-Snapshot y );
}
LL area (){
LL ans = 0;
For (int I = 1; I <= n; I ++)
Ans + = xmul (p [0], p [I], p [I + 1]);
Return ans <0? -Ans: ans;
}
Char str [1000005];
Int main (){
Int t;
Scanf ("% d", & t );
While (t --){
Scanf ("% s", str );
P [0]. x = 0; p [0]. y = 0;
For (n = 0; str [n + 1]; n ++ ){
Int dir = str [n]-'1 ';
P [n + 1]. x = p [n]. x + way [dir] [0];
P [n + 1]. y = p [n]. y + way [dir] [1];
}
LL ans = area ();
If (ans % 2 = 0) printf ("% I64d \ n", ans/2 );
Else printf ("% I64d. 5 \ n", ans/2 );
}
Return 0;
}