日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa 11520 Fill the Square 填充正方形

發布時間:2025/7/14 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVa 11520 Fill the Square 填充正方形 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

在一個 n * n 網格中填了一些大寫字母,你的任務是把剩下的格子中也填滿大寫字母,使得任意兩個相鄰格子(即有公共邊的格子)中的字母不同。如果有多重填法,則要求按照從上到下,從左到右的順序把所有格子連接起來得到的字符串的字典序應該盡量小。

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

因為要保證字符串的字典序最小,所以就從第一行第一列開始,一行一行的暴就搞定了。其他的就不說了,簡單的水題。

附AC代碼:

1: #include <stdio.h> 2: #include <math.h> 3: #include <iostream> 4: #include <cstdarg> 5: #include <algorithm> 6: #include <string.h> 7: #include <stdlib.h> 8: #include <string> 9: #include <list> 10: #include <vector> 11: #include <map> 12: #define LL long long 13: #define M(a) memset(a, 0, sizeof(a)) 14: using namespace std; 15:? 16: void Clean(int count, ...) 17: { 18: va_list arg_ptr; 19: va_start (arg_ptr, count); 20: for (int i = 0; i < count; i++) 21: M(va_arg(arg_ptr, int*)); 22: va_end(arg_ptr); 23: } 24:? 25: char buf[19][19]; 26:? 27: char Deal(int a, int b) 28: { 29: for (char tmp = 'A'; tmp <= 'Z'; tmp++) 30: { 31: if (buf[a - 1][b] == tmp) continue; 32: else if (buf[a + 1][b] == tmp) continue; 33: else if (buf[a][b - 1] == tmp) continue; 34: else if (buf[a][b + 1] == tmp) continue; 35: else return tmp; 36: } 37: } 38:? 39: int main() 40: { 41: int T, n, cnt = 1; 42: scanf("%d", &T); 43: while(T--) 44: { 45: scanf("%d", &n); 46: Clean(1, buf); 47: char *input = &buf[1][1]; 48: for (int i = 1; i <= n; i++) 49: { 50: input = &buf[i][1]; 51: scanf("%s", input); 52: } 53: for(int i = 1; i <= n; i++) 54: { 55: for (int j = 1; j <= n; j++) 56: { 57: if (buf[i][j] == '.') 58: buf[i][j] = Deal(i, j); 59: } 60: } 61: printf("Case %d:\n", cnt++); 62: for(int i = 1; i <= n; i++) 63: { 64: for (int j = 1; j <= n; j++) 65: printf("%c", buf[i][j]); 66: puts(""); 67: } 68: } 69: return 0; 70: }

轉載于:https://www.cnblogs.com/wuhenqs/p/3234912.html

總結

以上是生活随笔為你收集整理的UVa 11520 Fill the Square 填充正方形的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。