UVA 1605 Building for UN--联合国大厦
2017-06-16 10:34
330 查看
题意:修建一个长方体的联合国大厦,n个国家入驻,要求任意两个国家最少存在一对办公室相邻(相邻:隔一层墙或者一层天花板) 输出楼层H, 每层楼有w 行,l 列。
思路:参照紫书上的思路是,一共有两层,每层都是n*n的,第一层的第i行全是国家i,第二层的第j列全是国家j的。
AC代码:
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 52;
char a[maxn] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'
};
int main(){
int n;
while(scanf("%d",&n)==1){
printf("%d %d %d\n",2,n,n);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
printf("%c",a[i]);
if(j == n-1)printf("\n");
}
printf("\n");
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
printf("%c",a[j]);
if(j == n-1)printf("\n");
}
printf("\n");
}
return 0;
}
思路:参照紫书上的思路是,一共有两层,每层都是n*n的,第一层的第i行全是国家i,第二层的第j列全是国家j的。
AC代码:
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 52;
char a[maxn] = {
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'
};
int main(){
int n;
while(scanf("%d",&n)==1){
printf("%d %d %d\n",2,n,n);
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
printf("%c",a[i]);
if(j == n-1)printf("\n");
}
printf("\n");
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++){
printf("%c",a[j]);
if(j == n-1)printf("\n");
}
printf("\n");
}
return 0;
}
相关文章推荐
- 解题报告 之 UVA1605 Building for UN
- UVA_1605: Building for UN
- uva 1605 building for UN ——yhx
- UVA 1605(p236)----Building for UN
- UVA 1605 Building for UN
- UVA 1605 Building for UN(思维)
- UVa1605 Building for UN
- UVA1605 Building for UN (构造)
- uva 1605 ——Building for UN
- 联合国大楼UVA1605(Building for UN)
- UVa 1605 Building for UN ——思路题
- Uva1605 Building for UN 【构造法】【例题8-2】
- UVa 1605 Building for UN 【技巧】
- UVa1605 - Building for UN(构造法)
- 【例题 8-2 UVA-1605】Building for UN
- UVA 1605 - Building for UN
- 例题8-2 联合国大楼(Building for UN, ACM/ICPC NEERC 2007, UVa1605)
- uva 1605 building for UN ——yhx
- UVA1605-Building for UN
- uva 1605 Building for UN