UVA 11520 Fill the Square
来源:互联网 发布:csdn修改博客域名 编辑:程序博客网 时间:2024/04/28 22:48
第一篇题解
题意:一个n*n的网格里面填了些大写字母,把剩下的也填上,使得相邻的两个网格不相同,并且从左到右,从上到下连起来的字典序最小。
直接对每一个没填的网格依次考虑A到Z是否可以。
1 #include <cstdio> 2 #include <vector> 3 #include <algorithm> 4 #include <cstring> 5 6 using namespace std; 7 8 const int maxn = 10 + 5; 9 const int dx[] = {-1, 0, 0, 1};10 const int dy[] = {0, -1, 1, 0};11 char A[maxn][maxn];12 13 14 int main() {15 int T;16 17 scanf("%d", &T);18 for(int kase = 1; kase <= T; kase ++) {19 int n;20 scanf("%d", &n);21 22 for(int i = 1; i <= n; i++)23 scanf("%s", A[i]);24 25 for(int i = 1; i <= n; i++) {26 for(int j = 0; j < n; j++) if(A[i][j] == '.') {27 for(char k = 'A'; k <= 'Z'; k++) {28 int flag = 1;29 for(int d = 0; d < 4; d++) {30 int nx = i + dx[d];31 int ny = j + dy[d];32 if(nx > 0 && nx <= n && ny >= 0 && ny < n && A[nx][ny] != '.' && k == A[nx][ny]) {33 flag = 0;34 break;35 }36 }37 if(flag) {38 A[i][j] = k;39 break;40 }41 }42 }43 }44 45 printf("Case %d:\n", kase);46 for(int i=1; i <= n; i++)47 printf("%s\n", A[i]);48 }49 50 51 return 0;52 }
- 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 11520Fill 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
- UVa 11520 - Fill the Square
- UVA 11520 Fill the Square
- UVa 11520 - Fill the Square
- UVA 11520 Fill the Square .
- Fill the Square UVA
- .NET中TextBox控件设置ReadOnly=true后台取不到值三种解决方法
- arcgis 10 server 和desktop 安装注意总结
- SqlServer 事务与锁
- 教育办公系统的OpenSessionInView,通用翻页的实现
- test
- UVA 11520 Fill the Square
- HDU 4399 Query multiset 解法
- Ubuntu Eclipse 提示颜色
- LA 3902 UVA 1267 - Network
- linux 防火墙
- LA 3177 UVA 1335 - Beijing Guards
- UVA 11039 - Building designing
- UVA 1339 - Ancient Cipher
- Linux RedHat下添加自启动脚本的几种方式