1605 - Building for UN

Building for UN

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 number n(1n50) —— 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 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 exactly n 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

222
AB
CC

zz
zz

你的任务是设计一个包含若干层的联合国大楼,其中每层都是一个等大的网格。有若干国家需要在联合国大楼里办公,你需要把每个格子分配给一个国家,使得任意两个不同的国家都有一对相邻的格子(要么是同层中有公共边的格子,要么是相邻层的同一个格子)。你设计的大厦最多不能超过1000000个格子。

输入国家的个数n(n≤50),输出大楼的层数H、每层楼的行数W和列数L,然后是每层楼的平面图。不同国家用不同的大小写字母表示。例如,n=4的一组解是H=W=L=2,第一层是 ABCC ,第二层是 ZZZZ

#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main() {
    int n;
    while(cin >> n) {
        // 2层,每层n*n个格子
        int h = 2, w = n, l = n;
        int cell[h][w][l];
        memset(cell, 0, sizeof(cell));
        // 0层,第i列都是相同元素
        // 1层,第i行都是相同元素
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                for(int k = 0; k < l; k++) {
                    if(!i) {
                        cell[i][j][k] = k;
                    } else {
                        cell[i][k][j] = k;
                    }
                }
            }
        }
        // 输出
        // 这里注意字符数大于26个情况
        cout << h << " " << w << " " << l << endl;
        for(int i = 0; i < h; i++) {
            for(int j = 0; j < w; j++) {
                for(int k = 0; k < l; k++) {
                    int ch = cell[i][j][k];
                    if(ch < 26) {
                        printf("%c", cell[i][j][k] + 'A');
                    } else {
                        printf("%c", cell[i][j][k] + 'a' - 26);
                    }
                }
                cout << endl;
            }
            cout << endl;
        }
    }
    return 0;
}

你可能感兴趣的:(ACM,uva,UVa1605)