uva 1605 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
Input consists of several datasets. Each of them has 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 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 n different 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表示有多少个国家,现在要让你设计这样一栋楼,楼里面每个国家的办公室都要和其它国家的办公室相邻,每个国家的办公室可以有多个。让你输出方案。

#include <bits/stdc++.h>
using namespace std;
int Floor[51][51];
char country[51];
int main()
{
    ios::sync_with_stdio(false);
    for(int i=1;i<=50;i++)
    {
        for(int j=1;j<=50;j++)
        {
            Floor[i][j]=i;
        }
    }
    for(int i=0;i<25;i++)
    {
        country[i+1]='A'+i;
        country[i+26]='a'+i;
    }
    int n;
    while(cin>>n)
    {
        cout<<2<<" "<<n<<" "<<n<<endl;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            cout<<country[Floor[i][j]];
            cout<<endl;
        }
        cout<<endl;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            cout<<country[Floor[j][i]];
            cout<<endl;
        }
    }
    return 0;
}

题解:

可以联想到二维坐标系当中,如果每个国家的办公室用一条直线来表示,那么把所有国家都画上横线,如果有一条竖线一定会与所有横线都相交。所以只要设计两层楼,第一层所有国家都把自己的办公室按列摆放。第二层把所有国家的办公室按行摆放即可。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值