Reprint please indicate the source, thank you http://blog.csdn.net/ACM_cxlove? Viewmode = Contents
By --- cxlove
A: A very large farmland is provided. The farmer starts from the center and places he walks through will scatter pesticides. Pests can spread by 4 neighboring areas and ask how many farmland is not damaged. Http://codeforces.com/problemset/problem/243/C
I will say that I have been reading this question for a long time? Ah, I really regret that I did not report my name to Level 6 in the past two days. I am in a hurry to ask for a Level 6 certificate, but it is estimated that I have passed. Although the map is very large, but the path is limited, and relative to only fine strips, it directly becomes the area of the rectangle and. In addition, because it is a thin strip, it is directly discretization and then violent dyeing. Then, starting from the boundary, BFs searches to dye the pests that can be covered. Finally, the brute-force statistics continued, and finally it was quite fast. Oh, a maximum of 2000*2000.
# Include <iostream> # include <cstdio> # include <map> # include <cstring> # include <cmath> # include <vector> # include <stack> # include <algorithm> # include <set> # include <string> # include <queue> # define INF 0000000005ll # define M 1000005 # define n 1000005 # define maxn 2000005 # define EPS 1e-7 # define zero () FABS (a) <EPS # define min (A, B) (a) <(B )? (A) :( B) # define max (A, B) (a)> (B )? (A) :( B) # define Pb (a) push_back (a) # define MP (a, B) make_pair (a, B) # define MEM (A, B) memset (a, B, sizeof ()) # define ll long # define mod 1000000007 # define lson step <1 # define rson step <1 | 1 # define sqr (A) (a) * ()) # define key_value ch [CH [root] [1] [0] # define test puts ("OK"); # define PI ACOs (-1.0) # define lowbit (X) (x) & (-(X) # pragma comment (linker, "/Stack: 10241000000,1024000000") using namespace s TD; struct node {int x1, x2, Y1, Y2; node () {} node (INT _ X1, int _ Y1, int _ X2, int _ Y2 ): x1 (_ X1), y1 (_ Y1), X2 (_ x2), Y2 (_ Y2) {}} rec [1005]; int way [4] [2] = {2005, 0,-2005, 0,-}; int m; int vis [] [] = {0 }; vector <ll> X, Y; queue <pair <LL, ll> que; int ID (char ch) {If (CH = 'R') return 0; if (CH = 'l') return 1; if (CH = 'U') return 3; return 2;} int Bin (vector <ll> V, ll num) {return find (v. begin (), V. end (), num)-v. begin ();} int Mai N () {int X1 = 0, Y1 = 0, X2, Y2; scanf ("% d", & M); X. pb (-INF); X. pb (INF); Y. pb (-INF); Y. pb (INF); For (INT I = 0; I <m; I ++) {char STR [5]; int val; scanf ("% S % d ", & STR, & Val); int idx = ID (STR [0]); x2 = X1 + way [idx] [0] * val; y2 = Y1 + way [idx] [1] * val; X. pb (min (x1, x2); X. pb (max (x1, x2) + 1); Y. pb (min (Y1, Y2); Y. pb (max (Y1, Y2) + 1); REC [I] = node (min (x1, x2), min (Y1, Y2), max (x1, x2) + 1, max (Y1, Y2) + 1); X1 = x2; Y1 = Y2;} Sort (X. begin (), X. end (); sort (Y. begin (), Y. end (); X. resize (unique (X. begin (), X. end ()-X. begin (); Y. resize (unique (Y. begin (), Y. end ()-y. begin (); For (INT I = 0; I <m; I ++) {x1 = Bin (x, REC [I]. x1); x2 = Bin (x, REC [I]. x2)-1; Y1 = Bin (Y, REC [I]. y1); y2 = Bin (Y, REC [I]. y2)-1; for (Int J = x1; j <= x2; j ++) for (int K = Y1; k <= Y2; k ++) vis [J] [k] = 1;} que. push (MP (0, 0); vis [0] [0] = 2; while (! Que. empty () {pair <LL, ll> U, V; u = que. front (); que. pop (); For (INT I = 0; I <4; I ++) {v = u; V. first + = way [I] [0]; V. second + = way [I] [1]; If (v. first> = 0 & v. first <X. size () & v. second> = 0 & v. second <Y. size () & Vis [v. first] [v. second] = 0) {vis [v. first] [v. second] = 2; que. push (v) ;}} ll ans = 0; For (INT I = 0; I <X. size ()-1; I ++) for (Int J = 0; j <Y. size ()-1; j ++) if (vis [I] [J]! = 2) ans + = (LL) (X [I + 1]-X [I]) * (Y [J + 1]-y [J]); printf ("% i64d \ n", ANS); Return 0 ;}