UVA1605-Building for UN

Building for UN
Time limit: 3.000 seconds

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 (1$ \le$n$ \le$50) -- the number of countries that are hosted in the building.


Output 

On the first 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 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 ndifferent 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 

  
  
2 2 2
AB
CC
zz
zz
题意: 要求设计一个包含若干层的联合国大楼,其中每层都是一个等大的网格,若干国家需要在里面办公,你需要把每个格子分配给一个国家,使得任意格子的国家都有一个相邻的格子(同层中公共边的格子,上下相邻层的同一个格子),输入国家的个数,要求输出每一层的平面图.
算法分析:
因为题目基本没什么限制,层数和行数可以自由选择.因此,可以将其设计成行列都为 n ,高度为 2 的大楼!因此只需将第一层第 i 行和第二层第 j 行分给同一国家,则可以满足题目中所说的任意格子的国家都有一个相邻的格子!
代码实现:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <math.h>
#include <algorithm>
char str[100];

void solve(int z)
{
    for(int i = 0; i < z; i++)///第一层
    {
        for(int j = 0; j < z; j++)
        {
            if(i < 26)
                printf("%c",'A'+i);
            else
                printf("%c",'a'+i-26);
        }
        printf("\n");
    }
    printf("\n");
    for(int i = 0; i < z; i++)///第二层
    {
        for(int j = 0; j < z; j++)
        {
            if(j < 26)
                printf("%c",'A'+j);
            else
                printf("%c",'a'+j-26);
        }
        printf("\n");
    }
}

int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        printf("2 %d %d\n",n,n);
        solve(n);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值