uva 1605 building for UN ——yhx

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
oors, one on top of another.
Each
oor 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
oor and share a common wall,
or if one's
oor 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 number n (1  n  50) | the
number of countries that are hosted in the building.
Output
On the rst line of the output for each dataset write three integer numbers h, w, and l | height, width
and length of the building respectively.
h descriptions of
oors should follow. Each
oor description consists of l lines with w characters on
each line. Separate descriptions of adjacent
oors 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 exactly
n different countries in the building. In this problem the required building design always exists.
Print a blank line between test cases.

 1 #include<cstdio>
 2 #include<cstring>
 3 char turn(int x)
 4 {
 5     if (x<=26) return x+'a'-1;
 6     return x-27+'A';
 7 }
 8 int main()
 9 {
10     int i,j,k,m,n,p,q,x,y,z,l,h;
11     char c;
12     bool b=0;
13     while (scanf("%d",&n)==1)
14     {
15         if (b==0) b=1;
16         else printf("
");
17         printf("2 %d %d
",n,n);
18         for (i=1;i<=n;i++)
19         {
20             for (j=1;j<=n;j++)
21               printf("%c",turn(i));
22             printf("
");
23         }
24         printf("
");
25         for (i=1;i<=n;i++)
26         {
27             for (j=1;j<=n;j++)
28               printf("%c",turn(j));
29             printf("
");
30         }
31     }
32 }

和http://www.cnblogs.com/AwesomeOrion/p/5380752.html这道题一样,只是让你找到一组解。那我只要存心构造万能解即可。

我的方法是:建两层,每一层n*n,第一层横着按顺序排列1..n,第二层竖着按顺序排列1..n,这样每两个国家都会交叉。

原文地址:https://www.cnblogs.com/SBSOI/p/5575015.html