在一个 n * n 网格中填了一些大写字母,你的任务是把剩下的格子中也填满大写字母,使得任意两个相邻格子(即有公共边的格子)中的字母不同。如果有多重填法,则要求按照从上到下,从左到右的顺序把所有格子连接起来得到的字符串的字典序应该尽量小。

直接暴力走起就OK。因为,需要填的格子最多就是 A、B、C、D、E 这五个字母。所以直接暴力也就 O(n2

因为要保证字符串的字典序最小,所以就从第一行第一列开始,一行一行的暴就搞定了。其他的就不说了,简单的水题。

附AC代码:

#include <stdio.h>
#include <math.h>
#include <iostream>
#include <cstdarg>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <list>
#include <vector>
#include <map>
long
sizeof(a))
namespace std;
  15:  
int count, ...)
  17: {
  18:     va_list arg_ptr;
  19:     va_start (arg_ptr, count);
int i = 0; i < count; i++)
int*));
  22:     va_end(arg_ptr);
  23: }
  24:  
char buf[19][19];
  26:  
int b)
  28: {
'Z'; tmp++)
  30:     {
continue;
continue;
continue;
continue;
return tmp;
  36:     }
  37: }
  38:  
int main()
  40: {
int T, n, cnt = 1;
, &T);
while(T--)
  44:     {
, &n);
  46:         Clean(1, buf);
char *input = &buf[1][1];
int i = 1; i <= n; i++)
  49:         {
  50:             input = &buf[i][1];
, input);
  52:         }
int i = 1; i <= n; i++)
  54:         {
int j = 1; j <= n; j++)
  56:             {
'.')
  58:                     buf[i][j] = Deal(i, j);
  59:             }
  60:         }
, cnt++);
int i = 1; i <= n; i++)
  63:         {
int j = 1; j <= n; j++)
, buf[i][j]);
);
  67:         }
  68:     }
return 0;
  70: }

相关文章: