10339 - Problem 1   

Description

The simple Reversi is a strategy board game played on an 8x8 board. There are 64 identical disks, which are light on one side and dark on the other.
Given an initial play, find the best one move for 'L' so that the number of disks being flipped will be maximized.
The rules are the following:
1. Dark and light play in turns.
2. When a disk is placed and is faced up light(resp. dark), all of the dark(resp. light) disks between light disks are then turned over to become dark(resp. light).
3. ‘L’(resp. ‘D’) is shown when the disk is faced up light(resp. dark). The ‘-‘ is shown when there is no disk on the position.

Note that the following two conditions will not happen:
1. A disk is placed on a disk.
2. The disk placed did not turn over some disks.

For example, if the input is
- - - - - - - -
- - - - - - - -
- - L D - - - -
- - D D D - - -
- - D D L - - -
- - D - - - - -
- - - - - - - -
- - - - - - - -

then the best move for 'L' is
- - - - - - - -
- - - - - - - -
- - L D - - - -
- - L D D - - -
- - L D L - - -
- - L - - - - -
- - L - - - - -
- - - - - - - -

so the maximum number of flipped disks is 3

You may use the following piece of code:

#include 

#define B_SIZE 8

char board[B_SIZE][B_SIZE];

void read_board(){
    int i, j;

    for(i = 0; i < B_SIZE; i++){
        for(j = 0; j < B_SIZE; j++){
            scanf(" %c", &board[i][j]);
        }
    }
}

void print_board(){
    int i, j;

    for(i = 0; i < B_SIZE; i++){
        for(j = 0; j < B_SIZE; j++){
            printf(" %c", board[i][j]);
        }
        printf("\n");
    }
}

int main()
{
    read_board();

    /* your code here */

    /* print_board(); */

    return 0;
}

 

Input

The map.

Output

The maximum number of flipped disks.
Print a newline '\n' at the end.

Sample Input  Download

Sample Output  Download

Tags




Discuss