UVa1605 - Building for UN(构造法)
| Time Limit: 3000MS | Memory Limit: Unknown | 64bit IO Format: %lld & %llu |
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<tex2html_verbatim_mark> 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<tex2html_verbatim_mark>(1n
50)<tex2html_verbatim_mark> -- 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<tex2html_verbatim_mark> , w<tex2html_verbatim_mark> , and l<tex2html_verbatim_mark> -- height, width and length of the building respectively.
h<tex2html_verbatim_mark> descriptions of floors should follow. Each floor description consists of l<tex2html_verbatim_mark> lines with w<tex2html_verbatim_mark> 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<tex2html_verbatim_mark> 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 题解:
要求设计一个包含若干层的联合国大楼,其中每层都是一个等大的网格,若干国家需要在里面办公,你需要把每个格子分配给一个国家,使得任意格子的国家都有一个相邻的格子(同层中公共边的格子,上下相邻层的同一个格子),输入国家的个数,要求输出每一层的平面图.不要被题意迷惑。。。只需要设计两层就可以了,每个国家占第一层的每一行,占第二层的每一列,这样的话就既满足联通又相邻了。
#include <stdio.h>
#include <string.h>
int main()
{
int n;
while(scanf("%d",&n))
{
printf("2 %d %d\n",n,n);
for(int i=; i< n; i++) ///第一层
{
for(int j=; j<n; j++)
{
if(i<)
printf("%c",'A'+i);
else
printf("%c",'a'+i-);
}
printf("\n");
}
printf("\n");
for(int i=; i<n; i++) ///第二层
{
for(int j=; j<n; j++)
{
if(j<)
printf("%c",'A'+j);
else
printf("%c",'a'+j-);
}
printf("\n");
}
}
return ;
}
UVa1605 - Building for UN(构造法)的更多相关文章
- Uva 120 - Stacks of Flapjacks(构造法)
UVA - 120 Stacks of Flapjacks Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: %lld &a ...
- 利用子集构造法实现NFA到DFA的转换
概述 NFA非有穷自动机,即当前状态识别某个转换条件后到达的后继状态不唯一,这种自动机不便机械实现,而DFA是确定有限状态的自动机,它的状态转换的条件是确定的,且状态数目往往少于NFA,所以DFA能够 ...
- [Luogu4724][模板]三维凸包(增量构造法)
1.向量点积同二维,x1y1+x2y2+x3y3.向量叉积是行列式形式,(y1z2-z1y2,z1x2-x1z2,x1y2-y1x2). 2.增量构造法: 1)首先定义,一个平面由三个点唯一确定.一个 ...
- POJ 3295 Tautology (构造法)
Tautology Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7716 Accepted: 2935 Descrip ...
- 牛客网 牛客小白月赛2 A.数字方阵-反魔方阵,梁邱构造法
天坑未补... 水一波博客,再不写博客就咸成鱼干了,只写题不写题解,过一段时间就忘了自己学过什么了. 最近重点就是把开学以来写的题补出来,没学的就滚去学会啊(= =),填一下坑... 从这篇博客开始, ...
- 紫书 习题 8-24 UVa 10366 (构造法)
又是一道非常复杂的构造法-- #include<cstdio> #include<algorithm> #define REP(i, a, b) for(int i = (a) ...
- 紫书 例题8-17 UVa 1609 (构造法)(详细注释)
这道题用构造法, 就是自己依据题目想出一种可以得到解的方法, 没有什么规律可言, 只能根据题目本身来思考. 这道题的构造法比较复杂, 不知道刘汝佳是怎么想出来的, 我想的话肯定想不到. 具体思路紫书上 ...
- LeetCode42题,单调栈、构造法、two pointers,这道Hard题的解法这么多?
本文始发于个人公众号:TechFlow,原创不易,求个关注 今天是LeetCode专题的第23篇文章. 今天来看一道很有意思的题,它的难度是Hard,并且有许多种解法. 首先我们来看题面,说是我们有若 ...
- 【译】N 皇后问题 – 构造法原理与证明 时间复杂度O(1)
[原] E.J.Hoffman; J.C.Loessi; R.C.Moore The Johns Hopkins University Applied Physics Laboratory *[译]* ...
随机推荐
- reloadData should be in main thread
reloadData should be called in main thread, so if you call it in work thread, you should call it as ...
- Spring3 M2 quartz-2.1.7 解决bean不能注入问题
我们要达到这样的效果 public class CancelUnpaidOrderTask implements Job { @Autowired private AppOrderService or ...
- 趣解curl
Curl是Linux下一个很强大的http命令行工具,其功能十分强大. 1) 二话不说,先从这里开始吧! $ curl http://www.linuxidc.com 回车之后,www.linuxid ...
- struts2学习笔记(2)---Action中訪问ServletAPI获取Map类型的Servlet元素
源码: strust.xml <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts ...
- leetcode-WordLadder
Word Ladder Total Accepted: 10243 Total Submissions: 58160My Submissions Given two words (start and ...
- POJ 3414 Pots【bfs模拟倒水问题】
链接: http://poj.org/problem?id=3414 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=22009#probl ...
- struts 2学习笔记—初学struts 2
首先我学习了struts 1.x与struts 2的区别: 1.struts 1.x的控制器类必须从Action类继承. 2.struts 2的控制器类可以是一个普通的类,也可以是ActionSupp ...
- MyEclipse8.6安装svn(非link方式)
此方法经试验可行,暂时可以作为最佳解决方案. 本文所使用的MyEclipse版本为:8.6.1 svn的eclipse插件版本为:1.6.17,下载地址:http://subclipse.tigris ...
- IOS的工程目录结构和生命周期
IOS的工程目录结构和生命周期 ·simple table文件夹:工程相关源代码和配置文件 BIDAppDelegate : 委托的声明和实现 BIDViewController: 视图控 ...
- Oracle修改被占用的临时表结构
这两天在修改临时表的类型时,提示”attempt to create,alter or drop an index on temporary table already in use“的错误,由于临时 ...