After too much playing on paper, Iahub had switched to computer games. The game he plays is called "Block Towers". It's played in a rectangular grid with n rows and m columns (it contains nx? M cells). The goal of the game is to build your own city. Some cells in the grid is big holes, where iahub can ' t build any building. The rest of cells is empty. In some empty cell iahub can build exactly one tower of both following types:
blue Towers. Each have population limit equal to red towers. Each have population limit equal to
Iahub is also allowed to destroy a building from any cell. He can do this operation as much as he wants. After destroying a building, the other buildings is not influenced, and the destroyed cells becomes empty (so Iahub can bu ILD a tower in this cell if needed, see the second example for such a case).
Iahub can convince as many population as he wants to come into the he city. So he needs to configure the maximum population possible. Therefore He should find a sequence of operations that builds the city on an optimal-in-a-do, so-total population limit I s as large as possible.
He says he ' s the best at this game, but he doesn ' t has the optimal solution. Write A program this calculates the optimal one, to show him that he's not as good as he thinks.
Input
The first line of the input contains the integersNandm(1?≤? n,? m? ≤?500). Each of the nextNLines containsmCharacters, describing the grid. TheJ-th character in theI-th line is '.' If you ' re allowed-to-build at the cell with coordinates(i,? J)A tower (empty cell) or '#' If there is a big hole there.
Output
Print an integer K on the first line (0?≤? K. ≤?106) -the number of operations Iahub should perform to obtain optimal result.
Each of the following K lines must contain a single operation in the following format:
- ? B x y? (1?≤? ) x? ≤? n,? 1?≤? y? ≤? m) -building a blue tower at the cell (x,? Y);
- ?r x y ? ( x ,? Y ) ;
- ? D x y? (1?≤? ) x? ≤? n,? 1?≤? y? ≤? m) -destroying a tower at the cell (x,? Y).
If There is multiple solutions you can output any of them. Note, that's you shouldn ' t minimize the number of operations.
Sample Test (s) input
2 3..#.#.
Output
4 B 1 1R 1 2R 2 1 B 2 3
Input
1 3 ...
Output
5 B 1 1 B 1 2R 1 3D 1 2R 1 2
Idea: For each of the. Unicom block, there is only one figure B, the other first Tu b again map around, and then figure D, then figure R
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < cmath> #include <queue> #include <stack> #include <vector> #include <set> #include <map > #define L (x) (x<<1) #define R (x) (x<<1|1) #define MID (x, y) ((x+y) >>1) #define EPS 1e-8typedef __ Int64 ll; #define FRE (i,a,b) for (i = A; I < b; i++) #define MEM (T, v) memset ((t), V, sizeof (t)) #define SF (n) s CANF ("%d", &n) #define SFF (A, b) scanf ("%d%d", &a, &b) #define SFFF (a,b,c) scanf ("%d%d%d", &a, &b, &C) #define PF printf#define Bug pf ("hi\n") using namespace std; #define INF 0x3f3f3f3f#define N 505stru CT stud{Stud (char a,int x,int y): x (x), Y (y), ch (a) {} stud () {} int x, y; Char ch; void print () {printf ("%c%d%d\n", ch,x,y);}} F[n*n*3];int k;int step[4][2]={1,0,-1,0,0,1,0,-1};int N,m;char a[n][n];int vis[n][n];inline bool Judge (int x,int y) { Return x>=1&&x<=n&&y>=1&&y<=m;} void Dfs (int x,int y,int dep) {a[x][y]= ' # '; F[k++]=stud (' B ', x, y); int i,j; Fre (i,0,4) {int xx=x+step[i][0]; int yy=y+step[i][1]; if (judge (xx,yy) &&a[xx][yy]== '. ') {DFS (xx,yy,1);} } if (DEP) {F[k++]=stud (' D ', x, y); F[k++]=stud (' R ', x, y);}} int main () {int i,j;while (~SFF (n,m)) {k=0;for (i=1;i<=n;i++) scanf ("%s", a[i]+1), Fre (i,1,n+1) fre (j,1,m+1) if (a[i][j ]=='.') {DFS (i,j,0);} PF ("%d\n", k); for (i=0;i<k;i++) F[i].print ();} return 0;}
cf327d (DFS)