zoukankan      html  css  js  c++  java
  • ACM学习历程—BNUOJ3685 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

    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);
        for (int i = 0; i < n; ++i)
        {
            for (int j = 0; j < n; ++j)
                printf("%c", item[j]);
            printf("
    ");
        }
        printf("
    ");
        for (int i = 0; i < n; ++i)
            {
            for (int j = 0; j < n; ++j)
                printf("%c", item[i]);
            printf("
    ");
        }
    }
    
    int main()
    {
        //freopen("test.in", "r", stdin);
        init();
        while (scanf("%d", &n) != EOF)
            output();
        return 0;
    }
  • 相关阅读:
    英雄联盟离线更新方法
    (七) Keras 绘制网络结构和cpu,gpu切换
    剑指offer | 链表中的倒数第K个结点 | 12
    剑指offer | 从尾到头打印链表 | 11
    剑指offer | 栈的压入,弹出序列 | 10
    剑指offer | 包含min函数的栈 | 09
    剑指offer | 调整数组顺序使奇数位于偶数前面 | 08
    剑指offer | 旋转数组的最小数字 | 07
    剑指offer | 两个栈实现一个队列 | 06
    剑指offer | 替换空格 | 05
  • 原文地址:https://www.cnblogs.com/andyqsmart/p/4856281.html
Copyright © 2011-2022 走看看