程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> UVa1605,

UVa1605,

編輯:關於C語言

UVa1605,


UVA - 1605

  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>(1$ \le$n$ \le$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=0; i< n; i++) ///第一層
        {
            for(int j=0; j<n; j++)
            {
                if(i<26)
                    printf("%c",'A'+i);
                else
                    printf("%c",'a'+i-26);
            }
            printf("\n");
        }
        printf("\n");
        for(int i=0; i<n; i++) ///第二層
        {
            for(int j=0; j<n; j++)
            {
                if(j<26)
                    printf("%c",'A'+j);
                else
                    printf("%c",'a'+j-26);
            }
            printf("\n");
        }
    }
    return 0;
}

 

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved