ACM学习历程—BNUOJ3685 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
The input file consists of 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 file 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.
Sample Input
4
Sample Output
2 2 2
AB
CC
zz
zz
题目大意是把一个矩形分成h层w行l列,然后往里面放元素,同一种元素一定要全部相邻,不同种元素要两两相接触。
这里的相邻只要同一层相邻或者不同层上下相邻都行。
一种构造的方法是:
构造两层,
让每一个元素占据第一层某一行,第二层的某一列。
这种方法是满足条件的,不要被样例的方法迷惑了。
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#define LL long long using namespace std; int n, item[]; void init()
{
for (int i = ; i < ; ++i)
item[i] = 'a'+i;
for (int i = ; i < ; ++i)
item[i] = 'A'+i-;
} void output()
{
printf("2 %d %d\n", n, n);
for (int i = ; i < n; ++i)
{
for (int j = ; j < n; ++j)
printf("%c", item[j]);
printf("\n");
}
printf("\n");
for (int i = ; i < n; ++i)
{
for (int j = ; j < n; ++j)
printf("%c", item[i]);
printf("\n");
}
} int main()
{
//freopen("test.in", "r", stdin);
init();
while (scanf("%d", &n) != EOF)
output();
return ;
}
ACM学习历程—BNUOJ3685 Building for UN(构造)的更多相关文章
- ACM学习历程—Hihocoder 1291 Building in Sandbox(dfs && 离线 && 并查集)
http://hihocoder.com/problemset/problem/1291 前几天比较忙,这次来补一下微软笔试的最后一题,这题是这次微软笔试的第四题,过的人比较少,我当时在调试B题,没时 ...
- ACM学习历程—FZU 2140 Forever 0.5(计算几何 && 构造)
Description Given an integer N, your task is to judge whether there exist N points in the plane su ...
- 完成了C++作业,本博客现在开始全面记录acm学习历程,真正的acm之路,现在开始
以下以目前遇到题目开始记录,按发布时间排序 ACM之递推递归 ACM之数学题 拓扑排序 ACM之最短路径做题笔记与记录 STL学习笔记不(定期更新) 八皇后问题解题报告
- ACM学习历程—UESTC 1222 Sudoku(矩阵)(2015CCPC H)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目大意就是构造一个行列和每个角的2*2都是1234的4*4矩阵. 用dfs暴力搜索,不过需要每一步进 ...
- ACM学习历程—UESTC 1226 Huatuo's Medicine(数学)(2015CCPC L)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1226 题目就是构造一个对称的串,除了中间的那个只有1个,其余的两边都是对称的两个,自然答案就是2*n-1. ...
- ACM学习历程—HDU 5512 Pagodas(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5512 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是给了初始的集合{a, b},然后取集合里 ...
- ACM学习历程—HDU5521 Meeting(图论)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5521 学习菊苣的博客,只粘链接,不粘题目描述了. 题目大意就是一个人从1开始走,一个人从n开始走.让最 ...
- ACM学习历程——UVA11234 Expressions(栈,队列,树的遍历,后序遍历,bfs)
Description Problem E: Expressions2007/2008 ACM International Collegiate Programming Contest Unive ...
- ACM学习历程—HDU2476 String painter(动态规划)
http://acm.hdu.edu.cn/showproblem.php?pid=2476 题目大意是给定一个起始串和一个目标串,然后每次可以将某一段区间染成一种字符,问从起始串到目标串最少需要染多 ...
随机推荐
- Jmeter + Ant + Jenkins 接口/性能测试,持续集成环境搭建
1. 安装Jmeter.jdk Jmeter 3.3版本 :<http://note.youdao.com/noteshare?id=5e3fd287db24d08386207a7de22d26 ...
- WCF基础之序列化
wcf是基于消息进行通信的,这篇就是简单说下序列化引擎是如何将.net object转化为xml消息.一般情况下很少用到这些,你只需定义数据协定之类的或者指定相应的序列化引擎,然后设置相应的特性就好. ...
- POJ 2993 Emag eht htiw Em Pleh【模拟画棋盘】
链接: http://poj.org/problem?id=2993 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27454#probl ...
- But what exactly do we mean by "gets closer to"?
https://rdipietro.github.io/friendly-intro-to-cross-entropy-loss/ [将输入转化为输出:概率分布] When we develop a ...
- ShowModal 代码分析
下面为Delphi中,方法TCustomForm.ShowModal的代码,通过分析以下代码,可以了解ShowModal到底是怎么一回事! 1 2 3 4 5 6 7 8 9 10 11 12 13 ...
- shell脚本调试运行
1.在命令行提供参数:$sh -x script.sh 但是有的shell脚本只能用 ./xxx.sh的方式运行,不能用sh命令解析执行.则此方法会报错.2.脚本开头提供参数:#!/bin/sh ...
- Django 路飞学成书写规范的总结
路飞学成书写规范的总结 命名 项目/文件/函数 -> 小写+下划线 类 驼峰式 路由 将每个功能的路由进行分割, 或者做上注释 类和方法的注释 每个类都要注释是干什么的 每个方法也要进行注释标明 ...
- 波浪分析数据转换:大智慧、钱龙、胜龙可用Advanced GET ToGet 数据转换器V3.05特别版
http://www.55188.com/thread-4185427-1-1.html Advanced GET ToGet 数据转换器V3.05特别版,大智慧可用软件数据类型选“分析家”源软件数据 ...
- Data Structure Array: Maximum circular subarray sum
http://www.geeksforgeeks.org/maximum-contiguous-circular-sum/ #include <iostream> #include < ...
- zookeeper学习与实战(一)环境部署
[背景]:最近需要做这样一件事,在一台服务器上通过客户端生成配置文件,然后需要将该配置文件实时的传输到上百台应用服务器,供应用程序读取.同时,该配置文件是不定时更新内容,只要有更新,远程应用服务器应该 ...