zoukankan      html  css  js  c++  java
  • 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("
    ");
    17         printf("2 %d %d
    ",n,n);
    18         for (i=1;i<=n;i++)
    19         {
    20             for (j=1;j<=n;j++)
    21               printf("%c",turn(i));
    22             printf("
    ");
    23         }
    24         printf("
    ");
    25         for (i=1;i<=n;i++)
    26         {
    27             for (j=1;j<=n;j++)
    28               printf("%c",turn(j));
    29             printf("
    ");
    30         }
    31     }
    32 }

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

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

  • 相关阅读:
    WSGI应用程序示例
    UDP 网络程序-发送_接收数据
    【C语言】定义一个函数,求长方体的体积
    【C语言】输入三个正整数a,b,c,求最大值,要求定义一个计算最大值的函数max(a,b),返回a,b的值
    人工智能发展史-从图灵测试到大数据
    漫画 |《程序员十二时辰》,内容过于真实 ...
    漫画 | 外行对程序员误会有多深!
    爬虫究竟是合法还是违法的?
    【C语言】用指针作为形参完成数据的升序排列
    【C语言】数组名作函数参数,完成数据的升序排列
  • 原文地址:https://www.cnblogs.com/AwesomeOrion/p/5380764.html
Copyright © 2011-2022 走看看