Codeforces D-arthur and Walls

Source: Internet
Author: User

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

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.