Reprinted please indicate the source, thank youHttp://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove
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 it will be connected at the beginning and end, and there will be no crossover, but it is obviously not necessarily a convex polygon.
Http://poj.org/problem? Id = 1654
In fact, using the vector cross product to solve the polygon area is not only applicable to convex edges. The concave part is offset by positive and negative.
However, this question does not hate precision.
double cannot be crossed and must be an integer, the output area must be divided by 2. Therefore, 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, regardless of things
# 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 () (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 ;}