编程介的小学生 2019-05-08 11:43 采纳率: 20.5%
浏览 303

输入二进制的字符串代表插入的顺序,输出最小需要的球数量怎么利用C程序的编写的语言的代码实现?

Problem Description
Think about the Zuma Game. You have a row of at most 200 black(0) or white(1) balls on the table at the start. Each three consecutive balls never share the same colour. You also have infinite amount of black and white balls in your hand. On each turn, you can choose a ball in your hand and insert it into the row, including the leftmost place and the rightmost place. Then, if there is a group of three of more balls in the same colour touching, remove these balls. Keep doing this until no more balls can be removed.
Find the minimal balls you have to insert to remove all the balls on the table.

Input
The first line of input contains an integer T (1≤T≤100) which is the total number of test cases.
Each test case contains a line with a non-empty string of 0 and 1 describing the row of balls at the start.

Output
For each test case, output the case number and the minimal balls required to insert in a line.

Sample Input
4
10101
101001001
1001001001
01001101011001100

Sample Output
Case #1: 4
Case #2: 3
Case #3: 3
Case #4: 2

  • 写回答

1条回答 默认 最新

  • heymye 2019-05-08 15:23
    关注

    先统计下包含6个球的样式中的删除次序和删除方法,做个表。然后在输入的排列中,依次找出删除优先级最高的,先删除它然后重复这个动作。

    评论

报告相同问题?

悬赏问题

  • ¥200 关于#c++#的问题,请各位专家解答!
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥15 绘制多分类任务的roc曲线时只画出了一类的roc,其它的auc显示为nan
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀