Codeforces 525 D Arthur and Walls
Test instructions
Give a n*m table with ' * ' and '. ' To remove the least ' * ' and make '. ' The connected block that is located is a rectangle.
Limit:
1 <= n,m <= 2000
Ideas:
2*2 consider that if there is only one ' * ' in the lattice of 2*2, it means that the ' * ' should be removed, and no other cases will be removed. Then remove this ' * ' and then have an effect on the other four squares.
Complexity is very difficult to estimate.
/*codeforces 525 D Arthur and Walls test instructions: give a n*m table with ' * ' and '. ' To remove the least ' * ' and make '. ' The connected block that is located is a rectangle. limit: 1 <= n,m <= : 2*2 to consider, if the 2*2 of the lattice only a ' * ', indicating that the ' * ' to be removed, and other circumstances do not have to be removed. Then remove this ' * ' and then have an effect on the other four squares. complexity is very difficult to estimate. */#include <iostream> #include <cstdio>using namespace std;const int N=2005;char str[n][n];int n,m;void Gao ( int X,int y) {if (x==n-1 | | y==m-1 | | x<0 | | y<0) return; int tx,ty,s=0;for (int i=0;i<2;++i) for (int j=0;j<2;++j) if (str[x+i][y+j]== ' * ') {++s;tx=x+i;ty=y+j;} if (s==1) {str[tx][ty]= '. '; for (int i=-1;i<1;++i) for (int j=-1;j<1;++j) {Gao (tx+i,ty+j);}}} int main () {scanf ("%d%d", &n,&m), for (int i=0;i<n;++i) scanf ('%s ', Str[i]), for (int i=0;i<n-1;++i) for (int J=0;J<M-1;++J) {Gao (i,j);} for (int i=0;i<n;++i) puts (str[i]); return 0;}
Codeforces 525 D Arthur and Walls