uva 11520 - Fill the Square(贪心+枚举)
来源:互联网 发布:企业报表软件推荐 编辑:程序博客网 时间:2024/04/27 18:37
题目大意:给出一张图,'.'的地方要用大写字母去填,要求说每个位置的上下左右如果存在的话所填的字母不能和当前位置相同。输出从上到下,从左到右字典序最小的方案。
解题思路:从上到下,从左到右开始枚举,每次碰到'.'就从‘A’开始检测直到可以填入为止。
#include <cstdio>#include <cstring>int main() {int T, kase = 0;scanf("%d", &T);while (T--) {int n;char grid[15][15];scanf("%d", &n);for (int i = 0; i < n; i++)scanf("%s", grid[i]);for (int i = 0; i < n; i++)for (int j = 0; j < n; j++) {if (grid[i][j] == '.')for (char c = 'A'; c <= 'Z'; c++) {bool ok = true;if (i > 0 && grid[i-1][j] == c)ok = false;if (i < n - 1 && grid[i+1][j] == c)ok = false;if (j > 0 && grid[i][j-1] == c)ok = false;if (j < n - 1 && grid[i][j+1] == c)ok = false;if (ok) {grid[i][j] = c;break;}}}printf("Case %d:\n", ++kase);for (int i = 0; i < n; i++)printf("%s\n", grid[i]);}return 0;}
0 0
- uva 11520 - Fill the Square(贪心+枚举)
- uva 11520 - Fill the Square(贪心+枚举)
- uva 11520 Fill the Square(枚举)
- UVA - 11520 - Fill the Square(贪心)
- UVa 11520 Fill the Square(枚举)
- UVA 11520 - Fill the Square (贪心)
- uva 11520 - Fill the Square(枚举,2级)
- uva - 11520 - Fill the Square(贪心、字典序)
- Uva---11520Problem A Fill the Square (贪心+模拟)
- uva 11520 Fill the Square(DFS)
- UVa 11520 Fill the Square (贪心&字典序)
- uva 11520 - Fill the Square - D 填方块 贪心
- UVA 11520 - Fill the Square
- uva 11520 - Fill the Square
- uva 11520 Fill the Square
- Uva-11520-Fill the Square
- uva 11520 - Fill the Square
- UVA 11520 Fill the Square
- uvalive 3635 - Pie(二分搜索)
- Android网络编程之sax解析xml
- Cannot read property 'Store' of undefined nodejs express session
- Android处理键盘事件的小例子
- Android网络编程之pull解析xml
- uva 11520 - Fill the Square(贪心+枚举)
- CodeForces 159D Palindrome pairs (回文子串、dp)
- uva 1267 - Network(dfs)
- cxGrid拖动多选的方法
- 文章标题
- Pareto Chart – An Effective Graphical Tool to Resolve Problems
- uva 1335 - Beijing Guards(二分)
- LeetCode 139. Word Break
- Histogram as a Component of Seven Basic Quality Tool