F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Zuma

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)
Total Submission(s): 1857    Accepted Submission(s): 599


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\le T\le 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
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2025 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2025-04-01 07:31:30, Gzip enabled