• ZOJ 3465 The Hive




    The Hive

    Time Limit: 2 Seconds      Memory Limit: 65536 KB

    There is a hive in the village. Like this. There are 9 columns (from A to I) in this hive. Different column may have the different number of grids. Every grid has its own coordinate, which is form by a uppercase letter and a digit. The uppercase letter discribes which column the grid is, the digit discribes which row the grid is.

    ZOJ 3465 The Hive - qhn999 - 码代码的猿猿
    As the figure shows, column A has 7 grids, column B has 8 grids, column C has 9 grids, column D has 10 grids, column E has 11 grids, column F has 10 grids, column G has 9 grids, column H has 8 grids, column I has 7 grids. The grid in the bottom has the lowest row coordinate which is 0.

    There are 26 kinds of honey. At the beginning, all grids in the hive are empty. Everyday, the bee in this hive will drop a kind of honey from the top of one of these 9 columns. The lowest empty grid of this column will be filled with this kind of honey. And if the grid under it adjacently has the same kind of honey as it did, these two grids will generate a candy. And these two grids will be emptyimmediately.

    ZOJ 3465 The Hive - qhn999 - 码代码的猿猿

    Because these columns only have a few grids, they may be full one day. If the column the bee drops on is full, this drop will not affect the hive.

    Input

    There are multiple cases (<20).

    The first line containing an integer n (1 <= n <= 10000) indicates that the bee will work for n days. Following n lines, each line contains two charater. The fisrt one indicates which column will the bee drop the honey, the second charater indicates which kind of honey does the bee drop that day.

    Output

    First,print one line in the form "The number of candy is num_of_candy.". 
    And then, display the hive. Extra space at the end of line is not allowed.

    Sample Input

    5AEBHCIDFAE

    Sample Output

    The number of candy is 1.
             _
           _/ \_
         _/ \_/ \_
       _/ \_/ \_/ \_
     _/ \_/ \_/ \_/ \_
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/ \_/ \_/ \_/ \_/
    / \_/ \_/ \_/ \_/
    \_/H\_/ \_/ \_/ \_/
      \_/I\_/ \_/ \_/
        \_/F\_/ \_/
          \_/ \_/
            \_/


    Author: LIANG,Jiaxing
    Contest: ZOJ Monthly, January 2011


    #include <iostream>
    #include <cstdio>
    #include <cstring>

    using namespace std;

    char hive[9][12];
    int top[9];
    const int hi[9]={6,7,8,9,10,9,8,7,6};
    const int ku[9]={5,4,3,2,1,2,3,4,5};

    const char mpK[25][25]={
     "         _ ",
     "       _/ \_ ",
     "     \_/ \_/ \_ ",
     "   \_/ \_/ \_/ \\_ ",
     " _/ \_/ \_/ \_/ \_ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "/ \_/ \_/ \_/ \_/ \ ",
     "\_/ \_/ \_/ \_/ \_/ ",
      "  \_/ \_/ \_/ \_/ ",
     "    \_/ \_/ \_/ ",
      "      \_/ \_/ ",
     "        \_/ "
    };

    int main()
    {
        int n;
    while(scanf("%d",&n)!=EOF)
    {
        int cas=0;
        memset(hive,'.',sizeof(hive));
        memset(top,0,sizeof(top));

        char mp[25][25];
        memcpy(mp,mpK,sizeof(mpK));

        char st[3];
        for(int i=0;i<n;i++)
        {
            scanf("%s",st);
            int xx=st[0]-'A';
            if(top[xx]>hi[xx]) continue;
            if(hive[xx][top[xx]-1]==st[1])   {top[xx]--;cas++;}
            else hive[xx][top[xx]++]=st[1];
        }

        for(int i=0;i<9;i++)
            for(int j=0;j<top;j++)
               mp[22-ku-j*2][i*2+1]=hive[j];

        printf("The number of candy is %d. ",cas);
        for(int i=0;i<23;i++)
             printf("%s",mp);
    }
        return 0;
    }

  • 相关阅读:
    python 冒泡排序
    python 文件操作
    20180401 lambda表达式
    python 全局变量 局部变量
    python 参数
    window.open
    正则表达式
    应用环境操作
    python 十大经典排序算法
    W3C------JS
  • 原文地址:https://www.cnblogs.com/CKboss/p/3350927.html
Copyright © 2020-2023  润新知