Description
The United Nations has decided to build a new headquarters in Saint Petersburg, Russia. It will have a form of a rectangular parallelepiped and will consist of several rectangular floors, one on top of another. Each floor is a rectangular grid of the same dimensions, each cell of this grid is an office.
Two offices are considered adjacent if they are located on the same floor and share a common wall, or if one's floor is the other's ceiling.
The St. Petersburg building will host n national missions. Each country gets several offices that form a connected set.
Moreover, modern political situation shows that countries might want to form secret coalitions. For that to be possible, each pair of countries must have at least one pair of adjacent offices, so that they can raise the wall or the ceiling they share to perform secret pair-wise negotiations just in case they need to.
You are hired to design an appropriate building for the UN.
Input
Input consists of several datasets. Each of them has a single integer numbern(1n50) -- the number of countries that are hosted in the building.
Output
On the first line of the output for each dataset write three integer numbersh , w , andl -- height, width and length of the building respectively.
h descriptions of floors should follow. Each floor description consists ofl lines with w characters on each line. Separate descriptions of adjacent floors with an empty line.
Use capital and small Latin letters to denote offices of different countries. There should be at most 1 000 000 offices in the building. Each office should be occupied by a country. There should be exactlyn different countries in the building. In this problem the required building design always exists. Print a blank line between test cases.
Sample input
4
Sample output
2 2 2
AB
CC
zz
zz
题目大意:
建造一个新的总部,容纳n个国家,需要每个国家的各个房间互相连通且与别的每个国家至少有一个房间相连通。
解题思路:
题目可以理解为每一个国家在每一层楼各有一个房间,从纵向看,一个竖条都是一个国家。每个国家在某层的房间都通向其他国家的房间。
代码如下:
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
int n, i, j, k;
char ch[60];
for(i=0;i<26;i++)
ch[i]='A'+i;
for(j=0;j<26;j++,i++)
ch[i]='a'+j;
while(~scanf("%d", &n))
{
printf("%d %d 2\n",n,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",ch[j]);
printf("\n");
for(j=0; j<n; j++)
printf("%c", ch[i]);
printf("\n");
if(i!=n-1)printf("\n");
}
}
return 0;
}