首页 > 其他 > 详细

POJ 3566

时间:2014-07-17 20:37:04      阅读:412      评论:0      收藏:0      [点我收藏+]

Building for UN
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 1367   Accepted: 599   Special Judge

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

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

Source



题意:安排楼层(矩形格子)使各个国家啊都相邻,输出一种情况。

思路:每一层w=2,第一行是不同的n个国家,第二行都是某一个国家,这样保证了每个国家都与别的国家相邻。假设题目的4,结果就为
4 4 2
ABCD
AAAA

ABCD
BBBB

ABCD
CCCC

ABCD
DDDD

AC代码:
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner (System.in);
		char a[]=new char[60];
		int i,j;
		for(i=0;i<26;i++) a[i]=(char) ('A'+i);
		for(j=0;j<26;j++,i++) a[i]=(char) ('a'+j);
		while(scan.hasNext()){
			int n=scan.nextInt();
			System.out.println(n+" "+n+" "+2);
			for(i=0;i<n;i++){
				for(j=0;j<n;j++){
					System.out.print(a[j]);
				}
				System.out.println();
				for(j=0;j<n;j++){
					System.out.print(a[i]);
				}
				System.out.println();
				if(i!=n-1) System.out.println();
			}
		}
	}

}

POJ 3566,布布扣,bubuko.com

POJ 3566

原文:http://blog.csdn.net/kimi_r_17/article/details/37908495

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!