CodeForces 525D D. Arthur and Walls(BFS)
来源:互联网 发布:linux oracle安装教程 编辑:程序博客网 时间:2024/06/06 05:34
题目链接:http://codeforces.com/problemset/problem/525/D
题意:n*m的格子,‘*’代表墙壁,‘.’代表房间,要求房间都必须是矩形,输出改动后的 n*m;
思路:看了官方题解,思路蛮巧妙的。因为要求一定是矩形,所有在每个2*2的格子里,若有3个‘.’和1个‘*’,那么就将‘*’改成‘.’,这样就能确保房间一定是矩形了。
代码如下:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;const int N = 2010;int n , m;char map[N][N];void bfs(int x, int y){if(x == n-1 || y == m-1 || x < 0 || y < 0) return;int cnt = 0, tx, ty;for(int i = 0; i < 2; i++){for(int j = 0; j < 2; j++){if(map[x+i][y+j] == '*')cnt++, tx = x + i, ty = y + j;}}if(cnt == 1){map[tx][ty] = '.';for(int i = -1; i < 1; i++){for(int j = -1; j < 1; j++)bfs(tx + i, ty + j);}}}int main(){scanf("%d%d", &n, &m);for(int i = 0; i < n; i++)scanf("%s", map[i]);for(int i = 0; i < n-1; i++){for(int j = 0; j < m-1; j++){bfs(i,j);}}for(int i = 0; i < n; i++)printf("%s\n", map[i]);return 0;}
0 0
- CodeForces 525D D. Arthur and Walls(BFS)
- CodeForces - 525D Arthur and Walls(bfs)
- codeforces 525 D Arthur and Walls
- codeforces 525D Arthur and Walls
- Arthur and Walls - CodeForces 525 D 搜索
- Codeforces 525D Arthur and Walls 【DFS】
- Codeforces 525D Arthur and Walls 【DFS】
- Codeforces--525D--Arthur and Walls(DFS)
- DFS(思维) CodeForces - 525D Arthur and Walls
- D. Arthur and Walls (CF 525 D 搜索bfs)
- codefrces 525 D. Arthur and Walls (bfs-小矩形)
- 【CF】D. Arthur and Walls(BFS + 贪心)
- D. Arthur and Walls(Codeforces Round #297 (Div. 2) 搜索(BFS))
- Codeforces Round #297 (Div. 2) D Arthur and Walls(bfs)
- Codeforces 525D Arthur and Walls 【Dfs+思维】
- CodeForces 525D Arthur and Walls(DIV2 D) (DFS+YY)
- Codeforces Round #297 (Div. 2) D题. Arthur and Walls(BFS)
- Codeforces Round #297 (Div. 2)D. Arthur and Walls 搜索bfs
- 7.6 NOI模拟总结
- iOS中定时器NSTimer的一些用法总结
- ExtJs Alert
- 用JUnit4进行单元测试代码编写
- ios foundation
- CodeForces 525D D. Arthur and Walls(BFS)
- js format 加减
- iOS编程:学习篇(五)
- tomcat 与 HTTPS
- runtime原理
- innodb page页利用率
- 素数个数统计 使用位运算优化的 埃拉托色尼筛选法
- Power of Two
- Android开发之ScrollView中嵌套ListView的解决方案