解题报告 之 UVA1605 Building for UN

来源:互联网 发布:哈尔斯保温杯知乎 编辑:程序博客网 时间:2024/06/07 04:58

解题报告 之 UVA1605 Building for UN

Description

Download as PDF

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

今天终于发现了一道水题,但仍然没有实现一天3道的目标,呵呵哒。
题目大意:给出有多少个国家n(n<=50),需要给每个国家安排办公室。大楼的每一层有着相同的行列数,请你构造一种安排(输出层数,行数和列数),使得每两个国家之间都有一间挨着的办公室,且办公室总数不超过1000000,用不同字母表示不同国家,输出每层楼的安排方法。


此题感觉自由度很大,国家数量很少且房间很多(可以有1000000),所以最简单的想法就是:一共有n层,每层共有两行,第一行全部是国家i的办公室,第二行分别是国家1~n的办公室。即让国家i再第i层与其他所有国家相邻,然后就完事了。所以是很easy的。
BTW,大紫书上的做法是只有两层n*n,第一层第i行全是国家i,第二层第i列全是国家i,这样就是交替着来的,感觉其实是差不多的。所以根据n的不同直接输出结果即可。就是这么酷炫~


火爆爆的代码出锅咯:
#include <iostream>#include <algorithm>using namespace std;char letters[55];int main(){for (int i = 1; i <= 26; i++){letters[i] = 'A' + i - 1;}for (int i = 27; i <= 52; i++){letters[i] = 'a' + i - 27;}int n;while (cin >> n){cout << n << " " << n << " " << 2 << endl;for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++)cout << letters[i];cout << endl;for (int j = 1; j <= n; j++)cout << letters[j];cout << endl << endl;}}return 0;}

水题一道,刷刷就过了,see you next illusion~
另外恭喜SCU集训队专用VIP集训室盛大开业~虽然新钥匙打不开。

0 0
原创粉丝点击