解题报告 之 UVA1605 Building for UN
来源:互联网 发布:哈尔斯保温杯知乎 编辑:程序博客网 时间:2024/06/07 04:58
解题报告 之 UVA1605 Building for UN
Description
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(1n50) -- 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(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集训室盛大开业~虽然新钥匙打不开。
- 解题报告 之 UVA1605 Building for UN
- UVA1605-Building for UN
- UVa1605 Building for UN
- UVa1605 - Building for UN(构造)
- UVA1605 Building for UN (构造)
- UVa1605 Building for UN 构造
- 【Jason's_ACM_解题报告】Building for UN
- 联合国大楼UVA1605(Building for UN)
- Uva1605——Building for UN
- Uva1605 Building for UN 【构造法】【例题8-2】
- uva1605 - Building for UN 入门经典II 第八章例题8-2
- UVa1605 例题8-2 联合国大楼(Building for UN,ACM/ICPC NEERC 2007)
- 例题8-2 联合国大楼(Building for UN, ACM/ICPC NEERC 2007, UVa1605)
- B - Building for UN
- 1605 - Building for UN
- 1605 - Building for UN
- Building for UN
- UVA_1605: Building for UN
- 取汉字拼音首字母的方法
- WPF通过cs选择单元格,改变样式
- 理解lua 语言中的点、冒号与self
- Linux开发环境搭建与使用——ubuntu更新设置
- Sicily 7973. Hot Dogs in Manhattan
- 解题报告 之 UVA1605 Building for UN
- java线程池原理
- 连载:告诉你如何设计一个日访问量千万级别的系统,谈oracle的高级设计和开发(5)
- js读取表格单元格内容
- 删除字符串中的子串
- 浏览器的标准模式与怪异模式的设置与区分方法
- 学习博客
- 《C/C++学习指南(语法篇)》 - 关于本书
- Visual Studio 2012出现“无法访问T-SQL组件和安装了不兼容伯 DacFx版本”的解决办法