663 - CS135501_I2P2014_mid2 Scoreboard

Time

2014/12/15 15:30:00 2014/12/15 17:50:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10348 Four in a line
10349 license
10350 multiply transpose matrix

10348 - Four in a line   

Description

Connect Four( also known as Four in a line) is a classic two-player connection game. How to play it is described as follows:

1. Players chooses colors. In this example, player 1 chooses yellow and player 2 chooses red.

2. They take turns dropping discs from the top of a seven-column, six-row grid. In this example,
    player 1 drops a yellow disc first, and then player 2 drops a red disc, and so on.

3. The discs fall straight down, occupying the next available space within the column.

4. The player wins if he/she connects four of same colored discs, vertically, horizontally, or diagonally.


(From wikpedia: Connect Four)

Now, we will give you N moves. Please check who win the game or no result.

Note:
(1)    In this problem, the winner can only be determined on or after the N-th placement.
(2)    The coordinate of the board’s upper-left intersection is (0,0).

Hint:
Complete the following program.  You only need to write the ‘check result’ part.

#include 

char board[6][7];

void show_board(){
        int i, j;
        for( i = 0 ; i < 6 ; i++ ){
                for( j = 0 ; j < 7 ; j++ ){
                        printf( "%c", board[i][j] );
                }
                printf("\n");
        }
}

int main(){

        int i, j;
        int n, col, row;
        int win = 0;
        char color;

        // Initial
        for( i = 0 ; i < 6 ; i++ )
                for( j = 0 ; j < 7 ; j++ )
                        board[i][j] = '-';

        // Get moves
        scanf( "%d", &n );
        while( n-- ){
                getchar();
                scanf( "%d %c", &col, &color );
                // Put the disk
                col--; // Input is 1 ~ 7, but index is 0 ~ 6
		// Fall to the bottom
                for( row = 5 ; row >= 0 && board[row][col] != '-' ; --row );
                board[row][col] = color;
        }

        // check result
	/* Please insert your code here */

        if( win )
                printf("%c win\n", color);
        else
                printf( "No result\n" );
        show_board();

        return 0;

}

 

Input

The first line is an integer, describing the number of moves, N, 1≤ N ≤ 42. In the following N lines, each
line contains one number and one character: the number K specifies the column id,
and the character C specifies the color, 1≤K≤7 and C={Y, R}.

 

Output

The result of the game ( Y win, R win, No result ) and the final map.
Each entry of the map is printed by ‘ %c’, and there is a newline character at the end of the map.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




10349 - license   

Description

Problem Description

There are N license. Each license has four-digit integer. For example, if N=7, the input may look like

7

5566

1324

3578

4123

5656

4312

9841

We want to get the licenses that use the same digits and the digits should be sorted from small to large. For example, 1324, 4123, and 4312 are the combination of the same digits (1, 2, 3, and 4). We want to get 1234. Similarly, 5566 and 5656 are the combination of the same digits (5, 5, 6, and 6). We want to get 5566. 

For output, we list the modified licenses in an increasing order line by line, so the output will look 

1234

5566

 

You may consider the following algorithm:

0. Create a character array (char *str[5];) for storing the input integers and create an array which is initialed to zero (int HIT[10000];) to record the occurrences of input integers.

1. Read the number of input integers and store it in variable N (scanf("%d", &N);).

2. For each of the next N integers, do 

    2.1 Read the four-digit integer and store it as a four-character string in str.

    2.2 Use the bubble sort algorithm to rearrange the four characters.

    2.3 Convert the rearranged string to an integer m and increase the value of the corresponding element of the HIT array by 1 (HIT[m]++;).

3. Check each element of the HIT array; if its value is larger than 2, print the corresponding integer.

 

The bubble sort algorithm:

/* 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 first line contains a number N (1<=N<=100).

The next N lines provide the N four-digit integers.

Output

Each line shows a modified unique integer as explained in the problem description.

Remember to print a newline at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10350 - multiply transpose matrix   

Description

Given a matrix A, output the matrix multiply by its transpose matrix.

 
The transpose matrix of a matrix is created by the following rules:
1. If matrix A is n by m, the transpose matrix of A is m by n.
2. Put the rows of A as the columns of transpose matrix.
   or put the columns of A as the rows of transpose matrix.
Formally, the i th row, j th column element of AT, is the j th row, i th column element of A:
For example, if the matrix A is:
the transpose matrix of A is:
 
 
About matrix multiplication:
For matrix A(n by m) and matrix B(m by p),
the matrix product AB (denoted without multiplication signs or dots) is defined to be the n × p matrix
where each i, j entry is given by multiplying the entries Aik (across row i of A) by the entries Bkj (down column j of B), for k = 1, 2, ..., m, and summing the results over k:
(From wikpedia: Matrix multiplication)
 
Take our sample input for example:
Out11 = A11*AT11 + A12*AT21 = 1*1 + 4*4 = 17
Out12 = A11*AT12 + A12*AT22 = 1*2 + 4*5 = 22
Out13 = A11*AT13 + A12*AT23 = 1*3 + 4*6 = 27
Out21 = A21*AT11 + A22*AT21 = 2*1 + 5*4 = 22
Out22 = A21*AT12 + A22*AT22 = 2*2 + 5*5 = 29
Out23 = A21*AT13 + A22*AT23 = 2*3 + 5*6 = 36
Out31 = A31*AT11 + A32*AT21 = 3*1 + 6*4 = 27
Out32 = A31*AT12 + A32*AT22 = 3*2 + 6*5 = 36
Out33 = A31*AT13 + A32*AT23 = 3*3 + 6*6 = 45

Input

First line contains n and m, indicating that the matrix A is n by m.
Next, there will be n lines, each line will have m integers.
 
n m
A11 A12 ... A1m
A21 A22 ... A2m
...                     .
...                     .
...                     .
An1     ... ... Anm

 

Both n and m will be less than 10 and bigger than 1.

Output

Output the result of A multiplying with the transpose matrix of A.

Use "%5d" for each value.

Print newline at the end of each rows.

Sample Input  Download

Sample Output  Download

Tags




Discuss