codeforces D

这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,2000*2000的矩形,那么我们就可以知道了,只要是存在一个有点的区域应该尽量将他削为矩形,那么将这个图形进行缩放,最后我们知道只要存在一个2*2 的矩形中有1个是*就必须将这个*号去掉。 采用bfs去做

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <string.h>
 4 #include <cstdio>
 5 #include <queue>
 6 using namespace std;
 7 const int maxn = 2005;
 8 char ma[maxn][maxn];
 9 int num[maxn][maxn];
10 bool inq[maxn*maxn];
11 int tx[]={  0,-1, -1, -1, 0, 1, 1, 1 ,0};
12 int ty[]={ -1,-1,  0,  1, 1, 1, 0,-1 , -1};
13 int main()
14 {
15       int n,m;
16      while(scanf("%d%d",&n,&m)==2){
17             queue<int>Q;
18          for(int i=0; i<n; i++){
19             scanf("%s",ma[i]);
20             for(int j=0; j<m; j++)
21                  if(ma[i][j]=='.') {
22                    Q.push(i*m+j);
23                  }
24           }
25          while(!Q.empty()){
26              int id = Q.front(); Q.pop();
27              int xx = id/m, yy=id%m;
28              for(int i =0; i<8; i+=2){
29                  int sum=0,loc=-1;
30                  for(int j=i; j<i+3; j++){
31                         int dx = xx + tx[j];
32                  int dy = yy + ty[j];
33                  if(dx<0||dx>=n ||dy>=m||dy<0) 
34                     sum=4;
35                  if(ma[dx][dy]=='*')
36                     sum++,loc=dx*m+dy;
37                  if(sum>1)break;
38                  }
39                  if(sum==1){
40                          ma[loc/m][loc%m]='.'; Q.push(loc);
41                  }
42              }
43          }
44          for(int i=0; i<n; i++)
45              printf("%s
",ma[i]);
46      }
47     return 0;
48 }
原文地址:https://www.cnblogs.com/Opaser/p/4375457.html