UVa11520 Fill the Square (字典序枚举)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVa11520 Fill the Square (字典序枚举)相关的知识,希望对你有一定的参考价值。

链接:http://vjudge.net/problem/18268

分析:从上到下从左到右按字典序从小到大枚举。

 1 #include <cstdio>
 2 
 3 const int maxn = 10 + 5;
 4 
 5 int n;
 6 char grid[maxn][maxn];
 7 
 8 int main() {
 9     int T;
10     scanf("%d", &T);
11     for (int kase = 1; kase <= T; kase++) {
12         scanf("%d", &n);
13         for (int i = 0; i < n; i++) scanf("%s", grid[i]);
14         for (int i = 0; i < n; i++)
15             for (int j = 0; j < n; j++) if (grid[i][j] == .)
16                 for (char ch = A; ch <= Z; ch++) {
17                     if (i > 0 && grid[i - 1][j] == ch) continue;
18                     if (i < n - 1 && grid[i + 1][j] == ch) continue;
19                     if (j > 0 && grid[i][j - 1] == ch) continue;
20                     if (j < n - 1 && grid[i][j + 1] == ch) continue;
21                     grid[i][j] = ch; break;
22                 }
23         printf("Case %d:\n", kase);
24         for (int i = 0; i < n; i++) printf("%s\n", grid[i]);
25     }
26     return 0;
27 }

 

以上是关于UVa11520 Fill the Square (字典序枚举)的主要内容,如果未能解决你的问题,请参考以下文章

Uva 11520 - Fill the Square 贪心 难度: 0

UVA - 11520 - Fill the Square(贪心)

Uva 11520 填充正方形

UVA 11520 填充正方形

UVA - 11461-Square Numbers

UVA11470 Square Sums水题