Banner Home Page Web Contests Problems Ranklist Status Statistics

Reversi

Time Limit : 5000/2000ms (Java/Other)   Memory Limit : 65536/65536K (Java/Other)
Total Submission(s) : 97   Accepted Submission(s) : 39
Problem Description
Reversi, also called Othello, is a two-sided game.<br>Each of the two sides corresponds to one player; they are referred to here as light and dark after the sides of Othello pieces, but &quot;heads&quot; and &quot;tails&quot; would identify them equally as well, so long as each marker has sufficiently distinctive sides.<br>Originally, Reversi did not have a defined starting position. Later it adopted Othello's rules, which state that the game begins with four markers placed in a square in the middle of the grid, two facing light-up, two pieces with the dark side up. The dark player makes the first move.<br><img src=../../data/images/C288-1008-1.jpg><br><br>Dark must place a piece with the dark side up on the board, in such a position that there exists at least one straight (horizontal, vertical, or diagonal) occupied line between the new piece and another dark piece, with one or more contiguous light pieces between them. In the below situation, dark has the following options indicated by transparent pieces:<br><br><img src=../../data/images/C288-1008-2.jpg><br>After placing the piece, dark turns over (flips, captures) all light pieces lying on a straight line between the new piece and any anchoring dark pieces. All reversed pieces now show the dark side, and dark can use them in later moves—unless light has reversed them back in the meantime. In other words, a valid move is one where at least one piece is reversed.<br>If dark decided to put a piece in the topmost location (all choices are strategically equivalent at this time), one piece gets turned over, so that the board appears thus:<br><br><img src=../../data/images/C288-1008-3.jpg><br>Now light plays. This player operates under the same rules, with the roles reversed: light lays down a light piece, causing a dark piece to flip. Possibilities at this time appear thus (indicated by transparent pieces):<br><br><img src=../../data/images/C288-1008-4.jpg><br>Light takes the bottom left option and reverses one piece:<br><br><img src=../../data/images/C288-1008-5.jpg><br>Players take alternate turns. If one player cannot make a valid move, play passes back to the other player. When neither player can move, the game ends. This occurs when the grid has filled up, or when one player has no more pieces on the board, or when neither player can legally place a piece in any of the remaining squares. The player with the most pieces on the board at the end of the game wins.<br>Now after several rounds, it’s dark’s turn. Can you figure out the largest number of light pieces he can turn over?<br>
 

Input
The first line contains one integer T representing the number of test cases.<br>For each test case, there’re 8 lines. Each line contains 8 characters (D represents dark, L represents light, * represents nothing here).<br>Every two adjacent cases are separated by a blank line.<br>
 

Output
For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.<br>Please follow the format of the sample output.<br>
 

Sample Input
3<br>********<br>********<br>********<br>***LD***<br>***DL***<br>********<br>********<br>********<br><br>********<br>********<br>**DLL***<br>**DLLL**<br>**DLD***<br>********<br>********<br>********<br><br>********<br>********<br>*D******<br>*DLLD***<br>***LL***<br>**D*D***<br>********<br>********<br>
 

Sample Output
Case 1: 1<br>Case 2: 3<br>Case 3: 0<br>
 

Source
“光庭杯”第五届华中北区程序设计邀请赛 暨 WHU第八届程序设计竞赛
 

Statistic | Submit | Back