CODEFORCES 515D Drazil and Tiles <路径dfs + 跳格>
来源:互联网 发布:windows xp的外观设置 编辑:程序博客网 时间:2024/05/18 02:47
题目:http://codeforces.com/problemset/problem/515/D
题意:给你一张方格,叫你用1X2填充方格,有些方格已经被占了(用‘*’),没被占的('.')。竖起来填,用 "^v"表示,横起来,用”<>"表示。如果放的方法独一无二,输出放好的方格图。否则输出“Not unique".
分析:dfs一下,一对一对地找。
Input
3 3
...
.*.
...
Output
Not unique
Input
4 4
..**
*...
*.**
....
Output
<>**
*^<>
*v**
<><>
#include <bits/stdc++.h>using namespace std;int const MAX = 2010;char s[MAX][MAX];int n, m, cnt;int dx[4] = {0, 0, 1, -1};int dy[4] = {1, -1, 0, 0};void dfs(int x, int y){ if(x < 1 || x > n || y < 1 || y > m || s[x][y] != '.') return; int dir = -1, sum = 0; for(int i = 0; i < 4; i++) { int xx = x + dx[i]; int yy = y + dy[i]; if(s[xx][yy] == '.') { sum ++; dir = i; } } if(sum == 1) { if(dir == 0) { s[x][y] = '<'; s[x][y + 1] = '>'; } else if(dir == 1) { s[x][y] = '>'; s[x][y - 1] = '<'; } else if(dir == 2) { s[x][y] = '^'; s[x + 1][y] = 'v'; } else if(dir == 3) { s[x][y] = 'v'; s[x - 1][y] = '^'; } cnt += 2; for(int i = 0; i < 4; i++) dfs(x + dx[dir] + dx[i], y + dy[dir] + dy[i]); }}void init(){ cnt = 0; for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) if(s[i][j] == '*') cnt ++;}int main(){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; i++) scanf("%s", s[i] + 1); init(); for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) dfs(i, j); if(cnt == n * m) { for(int i = 1; i <= n; i++) { printf("%s\n", s[i] + 1); } } else printf("Not unique\n"); return 0;}
0 0
- CODEFORCES 515D Drazil and Tiles <路径dfs + 跳格>
- codeforces 515D Drazil and Tiles
- codeforces 515d Drazil and Tiles
- 【codeforces】515-D Drazil and Tiles
- codeforces 515D Drazil and Tiles
- Drazil and Tiles - CODEFORCES 515D 贪心
- Drazil and Tiles(CodeForces 515D)
- Codeforces 515D - Drazil and Tiles (拓扑排序)
- codeforces 515D Drazil and Tiles(构造)
- Drazil and Tiles - CodeForces 513 D 搜索
- 【CF 515D】 Drazil and Tiles
- Codeforces Round #292 (Div. 2)D. Drazil and Tiles
- codeforces#292-D. Drazil and Tiles-暴力/拓扑排序
- D. Drazil and Tiles (CF 515D bfs搜索)
- #292 (div.2) D.Drazil and Tiles
- 【codeforces 516B】Drazil and Tiles
- Codeforces Round #292 (Div. 2) -- D. Drazil and Tiles (拓扑排序)
- Codeforces Round #292 (Div. 2) -- D. Drazil and Tiles (拓扑排序)
- Git冲突:commit your changes or stash them before you can merge.
- 1004. 成绩排名 (20)
- LeetCode 111. Minimum Depth of Binary Tree
- Android Espresso测试Intents,WebView
- phpcms v9实现最后发布的文章后面 添加new 图标
- CODEFORCES 515D Drazil and Tiles <路径dfs + 跳格>
- HTML5拖拽实例(未测试)
- Linux shell命令
- httpClient中的三种超时设置
- LeetCode 104. Maximum Depth of Binary Tree
- android性能优化--如何分析anr及常用工具
- js合并单元格(未测试)
- ES6 对象的扩展 简单测试
- 离散数学:构造性二难推理和破坏性二难定理的解释