码迷,mamicode.com
首页 > 其他好文 > 详细

ACM学习历程—BNUOJ3685 Building for UN(构造)

时间:2015-10-05 21:58:56      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:

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 hw, 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 long

using 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(构造)

标签:

原文地址:http://www.cnblogs.com/andyqsmart/p/4856281.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!