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

Puzzle

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 751    Accepted Submission(s): 266


Problem Description
  One day, Resty gets a very interesting puzzle. Eve said that she will make a cake for Resty if he solved this puzzle, so Resty asks you to help him to solve the puzzle as soon as possible.
  As the figure, the puzzle is a rectangle divided into 4 * 6 = 24 squares. Each cell has a color of white / black/ grey. There are exactly 8 cells of each color. Our purpose is to make the middle 8 cells(which are not on the edge) have the same color by minimal steps.

Each step, you could choose a row or a column to shift it for 1 bit. As following:

Now, given the puzzle, you should help Resty find the minimal steps he must use to solve it.
 

Input
The first line is a number T, the number of test case.
Each case contains 4 lines, each line contains a 6-length string, describe a puzzle. B for black color, W for white and G for grey.
 

Output
For each test, output on line in the Format ¡°Case ID: ANS¡±, ANS should be the minimal number of steps to solve the puzzle.
 

Sample Input
3 GWGGWW BBBBBW GBBBGW WGGGWW GWGGWW BWBBBB GBBBGW WGGGWW WWWWWW BGGGGB WGGGGW BBBBBB
 

Sample Output
Case 1: 2 Case 2: 3 Case 3: 0
 

Author
Resty
 

Source
 

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