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>(1n50)<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 *[译]* ...
随机推荐
- 364. Nested List Weight Sum II
这个题做了一个多小时,好傻逼. 显而易见计算的话必须知道当前层是第几层,因为要乘权重,想要知道是第几层又必须知道最高是几层.. 用了好久是因为想ONE PASS,尝试过遍历的时候构建STACK,通过和 ...
- php异步请求模拟多进程
在A请求页面发起另一个B页面请求 不需要等待B页面执行结束再返回 直接往下执行A页面的请求 A页面代码 <?php $url = 'http://'.$_SERVER['HTTP_HOST']. ...
- WPF的进度条progressbar,运行时间elapse time和等待spinner的实现
今天用.NET 4.5中的TPL的特性做了个小例子,实现了WPF的进度条progressbar,运行时间elapse time和等待spinner. 先上图吧. 这个例子包含4个实现,分别是同步版 ...
- [AngularJS] Default Child state and nav between child state
Let's say we want a parent state which is a abstract state. Two children states, one is for sinlge a ...
- Marquee滚动字幕设置(转)
<marquee >滚动文字 </marquee> 方向 <direction=#> #=left, right,up,down 方式<bihavior=#& ...
- Qt 学习之路:线程和 QObject
前面两个章节我们从事件循环和线程类库两个角度阐述有关线程的问题.本章我们将深入线程间得交互,探讨线程和QObject之间的关系.在某种程度上,这才是多线程编程真正需要注意的问题. 现在我们已经讨论过事 ...
- iOS UIKit:viewController之定义(2)
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- sqlite使用blob类型存储/访问 结构体
/* open fire host and slora report data database */ int open_report_db(void) { ; char sql[SQL_COMMAN ...
- PRD产品需求文档概要
PRD概念 PRM就是Product Requirements Document的简称,也就是产品需求模型.一般来说一个产品会伴随有市场需求文档(Market Requirements Documen ...
- Java多线程——其他工具类CyclicBarrier、CountDownLatch和Exchange
CyclicBarrier 适用于:创建一组任务,它们并行地执行任务,然后在进行下一个步骤之前等待,直至所有任务完成.它使得所有的并行任务都将在栅栏处列队,因此可以一致地向前移动. 表示大家彼此等待, ...