广搜。看了官方题解才会的.....

定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块。

首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳过

改完之后,检查周围8个点是否是元素块,如果有新产生的元素块,那么压入队列。

这样操作完之后就是答案。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cmath>
  4. #include<vector>
  5. #include<queue>
  6. #include<algorithm>
  7. using namespace std;
  8.  
  9. struct Node
  10. {
  11. int a,b;
  12. Node(int A,int B){a=A,b=B;}
  13. };
  14. queue<Node>Q;
  15. const int N=;
  16. int n, m;
  17. char g[N][N];
  18.  
  19. bool check(int x, int y)
  20. {
  21. if (g[x][y] == '.' || x < || y < || x >= n || y >= m)return ;
  22. if (g[x][y - ] == '.'&&g[x - ][y - ] == '.'&&g[x - ][y] == '.')return ;
  23. if (g[x - ][y] == '.'&&g[x - ][y + ] == '.'&&g[x][y + ] == '.')return ;
  24. if (g[x][y + ] == '.'&&g[x + ][y + ] == '.'&&g[x + ][y] == '.')return ;
  25. if (g[x][y - ] == '.'&&g[x + ][y - ] == '.'&&g[x + ][y] == '.')return ;
  26. return ;
  27. }
  28.  
  29. void bfs()
  30. {
  31. for(int i=;i<n;i++)
  32. for(int j=;j<m;j++) if(check(i,j)) Q.push(Node(i,j));
  33.  
  34. while(!Q.empty())
  35. {
  36. Node h=Q.front(); Q.pop();
  37. if(!check(h.a,h.b)) continue;
  38. g[h.a][h.b]='.';
  39.  
  40. for(int i=-;i<=;i++)
  41. {
  42. for(int j=-;j<=;j++)
  43. {
  44. if(i==&&j==) continue;
  45. if(check(h.a+i,h.b+j)) Q.push(Node(h.a+i,h.b+j));
  46. }
  47. }
  48. }
  49. }
  50.  
  51. int main()
  52. {
  53. while (~scanf("%d%d", &n, &m))
  54. {
  55. for (int i = ; i < n; i++) scanf("%s", g[i]);
  56. bfs();
  57. for(int i=;i<n;i++) printf("%s\n",g[i]);
  58. }
  59. return ;
  60. }

CodeForces 525D Arthur and Walls的更多相关文章

  1. Codeforces Round #297 (Div. 2) 525D Arthur and Walls(dfs)

    D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input standard ...

  2. codeforces D - Arthur and Walls

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

  3. cf 525D.Arthur and Walls

    判断2*2的正方形,是不是3个"."1个"*"然后暴力bfs就好.(这种处理也是挺神奇的2333%%题解) #include<bits/stdc++.h& ...

  4. Codeforces Round #297 (Div. 2) D. Arthur and Walls [ 思维 + bfs ]

    传送门 D. Arthur and Walls time limit per test 2 seconds memory limit per test 512 megabytes input stan ...

  5. Codeforces Round #297 (Div. 2)D. Arthur and Walls 暴力搜索

    Codeforces Round #297 (Div. 2)D. Arthur and Walls Time Limit: 2 Sec  Memory Limit: 512 MBSubmit: xxx ...

  6. BFS Codeforces Round #297 (Div. 2) D. Arthur and Walls

    题目传送门 /* 题意:问最少替换'*'为'.',使得'.'连通的都是矩形 BFS:搜索想法很奇妙,先把'.'的入队,然后对于每个'.'八个方向寻找 在2*2的方格里,若只有一个是'*',那么它一定要 ...

  7. Arthur and Walls CodeForces - 525D (bfs)

    大意: 给定格点图, 每个'.'的连通块会扩散为矩形, 求最后图案. 一开始想得是直接并查集合并然后差分, 但实际上是不对的, 这个数据就可以hack掉. 3 3 **. .** ... 正解是bfs ...

  8. [BFS,大水题] Codeforces 198B Jumping on Walls

    题目:http://codeforces.com/problemset/problem/198/B Jumping on Walls time limit per test 2 seconds mem ...

  9. Codeforces 508E Arthur and Brackets 区间dp

    Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...

随机推荐

  1. erlang进程与操作系统线程

    erlang多进程与多线程: 在erlang开发中,我们面对的最小执行单位是进程,当然这个进程并不是系统层面上的进程,也不是线程.而是基于erlang运行时系统的一个进程.那么erlang的多进程是如 ...

  2. ORA-39070

    背景介绍: 项目以前建立的库,表空间文件文件比较多,问了一下dba,了解到表空间建立很多没有带来优惠(都在一块磁盘上),效率也不会提高:现在要进行新库的迁移(目前使用的是asm磁盘组rac集群),正好 ...

  3. Nginx访问限速配置方法详解

    开发测试阶段在本地限速模拟公网的环境,方便调试.投入运营会有限制附件下限速度,限制每个用户的访问速度,限制每个IP的链接速度等需求. 配置简单,只需3行,打开"nginx根目录/conf/n ...

  4. captche验证码

    JCaptcha 是一个用来生成验证码的开源Java类库 CaptchaServiceSingleton类(单态类) package com.dongbin.testy; import com.oct ...

  5. Eclipse/MyEclipse中常用快捷键总结

    1.格式化代码: Ctrl+Shift+F; 2.自动生成get/set方法:Shifi+Alt+S+R(按下空格是选中). 3.自动生成toString方法:Shifi+Alt+S+S(按下空格是选 ...

  6. Linux - CentOS6.5服务器搭建与初始化配置详解(下)

    传送带:Linux - CentOS6.5服务器搭建与初始化配置详解(上) 继续接着上面的安装,安装完后会出现下面界面 点击reboot重启 重启后可以看到下面的tty终端界面  因为这就是最小化安装 ...

  7. ThinkPad 禁用 触摸板

    执行 xinput wowk@wowk:~$ xinput ⎡ Virtual core pointer id=2 [master pointer (3)] ⎜ ↳ Virtual core XTES ...

  8. IE的CSS滤镜不过只支持IE可以创建幻灯片等一些炫酷的效果

    <img src="img/logo.png"  style="filter:xray"/>仅仅

  9. opewrt上传文件

    设备上运行的openwrt,当tftp和ftp都无法使用时,可以使用命令scp在两台linux设备上copy文件. 当设备启动起来后,输入命令: scp hbg@192.168.2.32:/home/ ...

  10. Thinkphp与Ucenter整合笔记

    ucenter手册:http://www.phpddt.com/manual/ucenter/html/index.htm 参考:http://www.thinkphp.cn/topic/1557.h ...