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]={
 "         _\n",
 "       _/ \\_\n",
 "     \_/ \\_/ \\_\n",
 "   \_/ \\_/ \\_/ \\\_\n",
 " _/ \\_/ \\_/ \\_/ \\_\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "/ \\_/ \\_/ \\_/ \\_/ \\\n",
 "\\_/ \\_/ \\_/ \\_/ \\_/\n",
  "  \\_/ \\_/ \\_/ \\_/\n",
 "    \\_/ \\_/ \\_/\n",
  "      \\_/ \\_/\n",
 "        \\_/\n"
};

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.\n",cas);
    for(int i=0;i<23;i++)
         printf("%s",mp );
}
    return 0;
}

转载于:https://www.cnblogs.com/CKboss/p/3350927.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值