BNUOJ 3685 Building for UN 联合国 【贪心】

题目链接:

  http://acm.bnu.edu.cn/v3/problem_show.php?pid=3685


贪心:

  有n个国家,要求你设计一栋楼并为这n个国家划分房间,要求相同国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的
  只需要设计两层就可以了,每个国家占第一层的每一行,占第二层的每一列,这样的话就既满足联通又相邻了


 1 #include<iostream>
 2 #include<algorithm>
 3 #include<cstdio>
 4 #include<cstring>
 5 using namespace std;
 6 char country[52];
 7 void Pre(){
 8     for(int i = 0; i < 26; i++) country[i] = 'A'+i;
 9     for(int i = 26; i < 52; i++) country[i] = 'a'+i-26;
10 }
11 
12 int main(){
13     Pre();
14     int n;
15     while(~scanf("%d", &n)){
16         printf("2 %d %d
", n, n);
17         for(int i = 0; i < n; i++){
18             for(int j = 0; j < n; j++){
19                 printf("%c", country[i]);
20             }
21             printf("
");
22         }
23         printf("
");
24         for(int i = 0; i < n; i++){
25             for(int j = 0; j < n; j++){
26                 printf("%c", country[j]);
27             }
28             printf("
");
29         }
30     }
31 
32     return 0;
33 }
原文地址:https://www.cnblogs.com/miaowTracy/p/4858713.html