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
Description
The input contains two polynomials f(x) and g(x).
f(x) = amxm + a(m-1)x(m-1) + ⋯ + a1x1 + a0x0
g(x) = bnxn + b(n-1)x(n-1) + ⋯ + b1x1 + b0x0
where m,n∈N, 0≤m,n≤10.
Compute h(x) = f(x)g(x).
Note that all the coefficients are integers.
Input
m
am a(m-1) … a1 a0
n
bn b(n-1) … b1 b0
Note that the coefficients are separated by a blank.
Output
The coefficients of h(x) in descending power order.
Use "%d " to print each coefficient and there is a newline at the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
The input contains three integers of the same length (same number of digits).
For example,
3412
5232
9128
For each integer, we rearrange its digits from small to large and produce a new integer. Therefore, the three integers above become
1234
2235
1289
The output shows the three integers in an increasing order, that is,
1234
1289
2235
You may use the following piece of code:
/* Using bubble sort to rearrange an array A[n] */
for (i = 0; i < n; i++) {
for (j = 1; j < n; j++) {
if (A[j-1] > A[j]) {
/* swap A[j-1] A[j] */
}
}
}
Input
The length of three integers, 1 ≤ length ≤ 9.
Three integers of the same length.
Output
Three rearranged integers in an increasing order.
Print a newline at the end of each integer.