编程介的小学生 2017-02-10 11:16 采纳率: 20.5%
浏览 975
已采纳

Zuma

Description

Zuma is one of my favorite games of Fantasy Games series. In the game a lot of balls of different colors will enter the screen continuous, and the balls onscreen are rolling by a fixed track in a queue. You can control the stone frog located at the center of screen to fire balls. The balls fired can be inserted into the rolling balls queue. When there is a group of 3 or more balls of the same color touching, they explode! You should eliminate all the balls before they reach the skull which lies on the end of the track.

Let’s consider a simplified game mode. There is a queue of balls of different colors given. At each time you can fire a ball of arbitrary color into the queue at arbitrary position (either between two balls or at one end of the queue). Arbitrary means that you can choose the color and the position on your behalf. When there is a group of M or more balls of the same color touching, they explode. Explosion causes the balls on either side to slide together, perhaps chain-reacting into another explosion.

There are some restrictions following:

You can only fire a ball of a certain color to a position where there is at least one ball of the same color touching. That is, after you fire the ball into the queue, there should be at least one ball of the same color touching the ball you fired.
There may be some groups of M or more balls of the same color touching at the initial situation. These balls will explode just when another ball (not belonging to the group but has the same color) or another group of balls of the same color touches them.
What is number of firings do you need at least to finish the game?

Input

Input contains multiple test cases. Each test case starts with an integer M (2 ≤ M ≤ 20) in one line. Following is one line of nonempty capital letters (A to Z). Each character specifies one ball of the color represented by the letter. The length of each line is no more than 200.

Output

There is one line for each test case, which is the number of firings you need at least to finish the game.

Sample Input

3
AAABAAA
3
ABBABBA
Sample Output

2
2

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-15 15:01
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大