The problem is to give a matrix, you must let the. Connected graph into a rectangle, 2000*2000 the rectangle, then we can know, as long as there is a bit of area should be as far as possible to cut him as a rectangle, then the graph is scaled, and finally we know that as long as there is a 2*2 in the rectangle there is a * This number must be removed. Use BFS to do
1#include <iostream>2#include <algorithm>3#include <string.h>4#include <cstdio>5#include <queue>6 using namespacestd;7 Const intMAXN =2005;8 CharMA[MAXN][MAXN];9 intNUM[MAXN][MAXN];Ten BOOLinq[maxn*MAXN]; One inttx[]={0,-1, -1, -1,0,1,1,1,0}; A intty[]={-1,-1,0,1,1,1,0,-1, -1}; - intMain () - { the intn,m; - while(SCANF ("%d%d", &n,&m) = =2){ -queue<int>Q; - for(intI=0; i<n; i++){ +scanf"%s", Ma[i]); - for(intj=0; j<m; J + +) + if(ma[i][j]=='.') { AQ.push (i*m+j); at } - } - while(!Q.empty ()) { - intID =Q.front (); Q.pop (); - intxx = id/m, yy=id%m; - for(inti =0; i<8; i+=2){ in intsum=0, loc=-1; - for(intJ=i; j<i+3; J + +){ to intDX = xx +Tx[j]; + intDy = yy +Ty[j]; - if(dx<0|| Dx>=n | | dy>=m| | dy<0) thesum=4; * if(ma[dx][dy]=='*') $sum++,loc=dx*m+dy;Panax Notoginseng if(sum>1) Break; - } the if(sum==1){ +ma[loc/m][loc%m]='.'; Q.push (Loc); A } the } + } - for(intI=0; i<n; i++) $printf"%s\n", Ma[i]); $ } - return 0; -}
Codeforces D-arthur and Walls