ACM學習曆程—BNUOJ3685 Building for UN(構造)

來源:互聯網
上載者:User

標籤:

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

The input file consists of a single integer number n (1 ≤ n ≤ 50) — the number of countries that are hosted in the building.

Output

On the first line of the output file write three integer numbers h, w, and l — height, width and length of the building respectively.

h descriptions of floors should follow. Each floor 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.

Sample Input
4
Sample Output
2 2 2
AB
CC
 
zz
zz

題目大意是把一個矩形分成h層w行l列,然後往裡面放元素,同一種元素一定要全部相鄰,不同種元素要兩兩相接觸。

這裡的相鄰只要同一層相鄰或者不同層上下相鄰都行。

一種構造的方法是:

構造兩層,

讓每一個元素佔據第一層某一行,第二層的某一列。

這種方法是滿足條件的,不要被範例的方法迷惑了。

 

 代碼:

#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <algorithm>#include <set>#include <map>#include <queue>#include <string>#define LL long longusing namespace std;int n, item[56];void init(){    for (int i = 0; i < 26; ++i)        item[i] = ‘a‘+i;    for (int i = 26; i < 52; ++i)        item[i] = ‘A‘+i-26;}void output(){    printf("2 %d %d\n", n, n);    for (int i = 0; i < n; ++i)    {        for (int j = 0; j < n; ++j)            printf("%c", item[j]);        printf("\n");    }    printf("\n");    for (int i = 0; i < n; ++i)        {        for (int j = 0; j < n; ++j)            printf("%c", item[i]);        printf("\n");    }}int main(){    //freopen("test.in", "r", stdin);    init();    while (scanf("%d", &n) != EOF)        output();    return 0;}

 

ACM學習曆程—BNUOJ3685 Building for UN(構造)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.