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;
    }
  • 相关阅读:
    Codeforces Round #481 (Div. 3)题解
    陕西师范大学第七届程序设计竞赛网络同步赛题解
    Codeforces Round #479 (Div. 3)题解
    2018年北京信息科技大学第十届程序设计竞赛暨ACM选拔赛题解
    江西财经大学第一届程序设计竞赛题解
    2018年湘潭大学程序设计竞赛G又见斐波那契
    2018年长沙理工大学第十三届程序设计竞赛题解
    JDBC连接SQL server2014代码
    数据定义伪指令语句
    JDBC连接数据库
  • 原文地址:https://www.cnblogs.com/andyqsmart/p/4856281.html
Copyright © 2011-2022 走看看