Codeforces 525 D Arthur and Walls

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.