Uva 1605 Building for UN【构造法】

题意:给出n个国家,给它们分配办公室,使得任意两个国家都有一对相邻的格子

看的紫书,最开始看的时候不理解 后来还是搜了题解--- 发现是这样的

比如说5个国家 应该输出

AAAA

BBBB

CCCC

DDDD

EEEE

ABCDE

ABCDE

ABCDE

ABCDE

ABCDE

按照这样的办法来放置就好了

 1 #include<iostream>  
 2 #include<cstdio>  
 3 #include<cstring> 
 4 #include <cmath> 
 5 #include<stack>
 6 #include<vector>
 7 #include<map> 
 8 #include<set>
 9 #include<queue> 
10 #include<algorithm>  
11 using namespace std;
12 
13 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
14 
15 typedef long long LL;
16 const int INF = (1<<30)-1;
17 const int mod=1000000007;
18 const int maxn=1000005;
19 
20 int main(){
21     int n;
22     while(scanf("%d",&n)!=EOF){
23         printf("2 %d %d
",n,n);
24         
25         for(int i=0;i<n;i++){
26             for(int j=0;j<n;j++){
27                 if(i<26) printf("%c",'A'+i);
28                 else printf("%c",'a'+i-26);
29             }
30             printf("
");            
31         }
32         printf("
");
33         
34         for(int i=0;i<n;i++){
35             for(int j=0;j<n;j++){
36                 if(j<26) printf("%c",'A'+j);
37                 else printf("%c",'a'+j-26);        
38             }
39             printf("
");
40         }
41     }
42     return 0;
43 }
View Code

话说距离第一看这题已经快两个月的说了诶----哎-------

goooooooooooooooooo------

原文地址:https://www.cnblogs.com/wuyuewoniu/p/4504285.html