这题说的是给了一个矩阵,必须让.连接起来的图形变成矩形,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 = ;
  8. char ma[maxn][maxn];
  9. int num[maxn][maxn];
  10. bool inq[maxn*maxn];
  11. int tx[]={ ,-, -, -, , , , ,};
  12. int ty[]={ -,-, , , , , ,- , -};
  13. int main()
  14. {
  15. int n,m;
  16. while(scanf("%d%d",&n,&m)==){
  17. queue<int>Q;
  18. for(int i=; i<n; i++){
  19. scanf("%s",ma[i]);
  20. for(int j=; 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 =; i<; i+=){
  29. int sum=,loc=-;
  30. for(int j=i; j<i+; j++){
  31. int dx = xx + tx[j];
  32. int dy = yy + ty[j];
  33. if(dx<||dx>=n ||dy>=m||dy<)
  34. sum=;
  35. if(ma[dx][dy]=='*')
  36. sum++,loc=dx*m+dy;
  37. if(sum>)break;
  38. }
  39. if(sum==){
  40. ma[loc/m][loc%m]='.'; Q.push(loc);
  41. }
  42. }
  43. }
  44. for(int i=; i<n; i++)
  45. printf("%s\n",ma[i]);
  46. }
  47. return ;
  48. }

codeforces D - Arthur and Walls的更多相关文章

  1. CodeForces 525D Arthur and Walls

    广搜.看了官方题解才会的..... 定义2*2的小矩阵,有三个是点,一个是星,这样的小矩阵被称为元素块. 首先把所有元素块压入队列,每次取出对头,检查是否还是元素块,如果是 那么将那个*改为点,否则跳 ...

  2. 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 ...

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

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

  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) 525D Arthur and Walls(dfs)

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

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

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

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

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

  8. Codeforces 508E Arthur and Brackets 区间dp

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

  9. Codeforces 101628A - Arthur's Language

    101628A - Arthur's Language 思路:dp,状态转移见代码. 代码: #include<bits/stdc++.h> using namespace std; #d ...

随机推荐

  1. dirname的用法:获取文件的父级目录路径

    命令:dirname 获取文件的路径(到父级目录)用法:dirname file_name [root@bogon opt]# a=$(dirname /mnt/a/b/c/d/a.sh) [root ...

  2. windows网卡共享网络时,报Internet连接共享访问被启用时,出现了一个错误。(null)

    今天笔者在自己电脑上作试验时,准备将无线网络连接共享给VMnet1时报Internet连接共享访问被启用时,出现了一个错误.(null)错误: 经上网查询到问题原因:没有启用 Windows Fire ...

  3. 【CF840C】On the Bench DP

    [CF840C]On the Bench 题意:给你一个长度为n的数组{ai},定义一个1到n的排列是合法的,当且仅当对于$1\le i <n$,$a_i\times a_{i+1}$不是完全平 ...

  4. python中的null值

    在一个没有接口文档的自动化测试中,只能通过抓包及查日志查看发送的信息,其中有一个接口发送的信息如下: enable_snapshot": true, "new_size" ...

  5. Unity3D Mecanim :Body Mask的使用、 角色Retargeting原理分析、Apply RootMotion

    一.Body Mask的使用 1.1.配置好骨骼后通过Muscles来微调角色骨骼中的运动范围,以避免角色在动画中的不正确的叠加或失真等现象. 1.2.身体遮罩BodyMask更形象的描述就是身体的开 ...

  6. SOA架构商城一

    SOA架构: SOA是Service-Oriented Architecture的首字母简称,它是一种支持面向服务的架构样式.从服务.基于服务开发和服务的结果来看,面向服务是一种思考方式.其实SOA架 ...

  7. 兵器簿之cocoaPods的安装和使用

    以前添加第三方库的时候总是直接去Github下载然后引入,但是如果这些第三方库发生了更新,我们还需要手动去更新项目,所以现在引入之前一直想弄都一直没有弄的cocoaPods,现在演示一把过程 其实非常 ...

  8. POJ--1050--To the Max(线性动规,最大子矩阵和)

    To the Max Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 44723 Accepted: 23679 Descript ...

  9. MyBatis学习(一)一个简单的例子

    mybatis入门例子 开发步骤: 1.创建java工程 2.加入jar包(依赖包.驱动包) 3.创建sqlMapConfig.xml 4.创建数据库,数据库表USER_C,插入测试记录 5.创建PO ...

  10. 0002python中dict和list的特殊构造

    >>> myinfor = {"name":"qiwsir","site":"qiwsir.github.io& ...