您的位置:首页 > 产品设计 > UI/UE

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: