uva 1605 building for UN ——yhx

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
oors, one on top of another.
Each
oor 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
oor and share a common wall,
or if one‘s
oor 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 n 50) | the
number of countries that are hosted in the building.
Output
On the rst 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
oors should follow. Each
oor description consists of l lines with w characters on
each line. Separate descriptions of adjacent
oors 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.
Print a blank line between test cases.

 1 #include<cstdio>
 2 #include<cstring>
 3 char turn(int x)
 4 {
 5     if (x<=26) return x+‘a‘-1;
 6     return x-27+‘A‘;
 7 }
 8 int main()
 9 {
10     int i,j,k,m,n,p,q,x,y,z,l,h;
11     char c;
12     bool b=0;
13     while (scanf("%d",&n)==1)
14     {
15         if (b==0) b=1;
16         else printf("\n");
17         printf("2 %d %d\n",n,n);
18         for (i=1;i<=n;i++)
19         {
20             for (j=1;j<=n;j++)
21               printf("%c",turn(i));
22             printf("\n");
23         }
24         printf("\n");
25         for (i=1;i<=n;i++)
26         {
27             for (j=1;j<=n;j++)
28               printf("%c",turn(j));
29             printf("\n");
30         }
31     }
32 }

和http://www.cnblogs.com/AwesomeOrion/p/5380752.html这道题一样,只是让你找到一组解。那我只要存心构造万能解即可。

我的方法是:建两层,每一层n*n,第一层横着按顺序排列1..n,第二层竖着按顺序排列1..n,这样每两个国家都会交叉。

时间: 2024-10-10 19:34:28

uva 1605 building for UN ——yhx的相关文章

(白书训练计划)UVa 1605 Building for UN(构造法)

题目地址:UVa 1605 一道答案特判的题.最简单的方法是只构造两层,第一层中第i行全是i国家,第二层中第i列全是i国家.这样就保证了所有的国家都会相邻. 代码如下: #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <stdlib.h> #include <math.h> #include <ctype.h&

UVa 1605 - Building for UN

链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4480 题意: 你的任务是设计一个包含若干层的联合国大楼,其中每层都是一个等大的网格.有若干国家需要在联合国大楼里办公,你需要把每个格子都分配给其中一个国家,使得任意两个不同的国家都有一对相邻的格子(要么是同层中相邻的格子,要么是相邻层的同一个格子),一个国家可以有多个相互连通的格子

UVA - 1605 Building for UN (联合国大楼)

题意:一个联合国大楼每层都有数量相等大小相同的格子,将其分配给n个国家,使任意两个不同的国家都相邻(同层有公共边或相邻层的同一个格子). 分析:可以设计一个只有两层的大楼,第一层每个国家占一行,第二层每个国家占一列,即每层都是n*n的. #pragma comment(linker, "/STACK:102400000, 102400000") #include<cstdio> #include<cstring> #include<cstdlib>

UVA 11636 Hello World,LA 3602 DNA Consensus String,UVA 10970 Big Chocolate,UVA 10340 All in All,UVA 11039 Building Designing

课程好紧啊,只能刷点水题了,几乎都是贪心. UVA 11636 Hello World 二的幂答案就是二进制长度减1,不是二的幂答案就是是二进制长度. #include<cstdio> int main() { int n,kas = 0; while(scanf("%d",&n),n>0){ int r = 0; for(n--;n;n>>=1) r++; printf("Case %d: %d\n",++kas,r); }

uva 11039 Building designing (排序)

uva 11039 Building designing An architect wants to design a very high building. The building will consist of some floors, and each floor has a certain size. The size of a floor must be greater than the size of the floor immediately above it. In addit

UVa 1605 (构造) Building for UN

题意: 有n个国家,要设计一栋长方体的大楼,使得每个单位方格都属于其中一个国家,而且每个国家都要和其他国家相邻. 分析: 紫书上有一种很巧妙的构造方法: 一共有2层,每层n×n.一层是每行一个国家,另一层是每列一个国家. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 50; 7 char b[2][max

UVA 11039 Building designing 贪心

题目链接:UVA - 11039 题意描述:建筑师设计房子有两条要求:第一,每一层楼的大小一定比此层楼以上的房子尺寸要大:第二,用蓝色和红色为建筑染色,每相邻的两层楼不能染同一种颜色.现在给出楼层数量和每层楼的尺寸(楼层尺寸的大小没有按照顺序给出),求出满足这样要求的最大楼层数. 算法分析:把楼层尺寸按照从大到小排序,然后遍历一次的同时记录相邻楼层所染颜色不同,把不满足要求的楼层去掉即可. 1 #include<iostream> 2 #include<cstdio> 3 #inc

UVa 1605 联合国大楼

https://vjudge.net/problem/UVA-1605 题意:有n个国家,要求设计一栋楼并为这n个国家划分房间,要求国家的房间必须连通,且每两个国家之间必须有一间房间是相邻的. 思路:乍一看很难的样子,但真的是很简单.一共只要两层,每层都是n*n的,第一层第i行全是国家i,第二层第j列全是国家j. 但是如果不是这样做的话好像还是挺难的. 1 #include<iostream> 2 #include<algorithm> 3 #include<string&g

UVa 11039 - Building designing

题目:有n个绝对值不为0的数字,从中找到一个序列,正负交替,绝对值递增,求序列最大长度. 分析:dp,动态规划.因为绝对值要递增,所以先按绝对值排序. 设前k个数组成大的序列最长为f(k),则有如下地推关系: f(k)= f(k-1)        { data[k]*data[k-1] > 0,最后量元素不同时取 } = f(k-1)+ 1  { data[k]*data[k-1] < 0,最后量元素同时取 } (所有数据均不相同,且不为零) 说明:(⊙v⊙). #include <a