1344 - I2P(I)2017_Chen_Lab4 Scoreboard

Time

2017/11/27 15:30:00 2017/11/27 17:45:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11697 Connect Four
11700 Stairs Climbing
11702 Flattening the Tree v2 - Preorder Traversal

11697 - Connect Four   

Description

Connect Four 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.

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

(Note: There is no draw (win-win) condition in this problem.)

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 <stdio.h>

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




11700 - Stairs Climbing   

Description

Bob is a man who wants to climb 3 step stairs.

Suppose he can only climb 1 or 2 step at a time.

Then , there are 3 possible ways to climb 3 step stairs

          (1)  1 step + 1 step + 1 step
          (2)  1 step + 2step
          (3)  2 step + 1step

The question is : if Bob want to climb X step stairs. 

How many possible ways are there to climp X step stairs.

Input

An integer N represents the number of testcases.

Then , there are following N lines.

Each line contain an integer X that  represents the number of stairs in that testcase.

P.S. 1<= X <=40

Output

An integer represents the number of possible way to climb N stairs.

Note that you have to add '\n' at the end of output

Sample Input  Download

Sample Output  Download

Tags




Discuss




11702 - Flattening the Tree v2 - Preorder Traversal   

Description

In this problem, we want you to use an array A to implement a perfect binary tree (a kind of binary tree which all interior nodes have two children and all leaves have the same depth or same level.). Given the level order sequence of the tree, please output the sequence of number after the tree is flattened. 

We call this flattening v2 "preorder traversal", which is another version of the origianl flattened tree.

For example, a perfect binary tree with level order sequence 4 2 6 1 3 5 7 looks like : 

After preorder traversal, so you should output 4 2 1 3 6 5 7. (Notice: This order is different from the homework)

 

[Hint]:

In the homework, the order of the output is inorder. (left child node -> root -> right child node)

In this problem, we need you to output the preorder sequence. (root -> left child node -> right child node)

 

 

Here is some tips for you guys to implement a binary tree.

1. A[1] is the root of the tree.

2. For the node locates in A[k], its left child locates in A[2k] and its right child locates in A[2k+1].

3. You can write a recursive function "find_seq" which takes the root index as its argument.

Input

The first line contains one integer n, representing the number of nodes in the tree.

The second line contains n integer ai, representing the level order of the tree.

It is guaranteed that :

  • n = 2k - 1
  • 1 ≤ k ≤ 10
  • a1 ~ an is a permutation of 1 ~ n

Output

Please output the sequence of number after the tree is traversal. Each number is separated by a whitespace.

Note that you have to add '\n' at the end of output

Sample Input  Download

Sample Output  Download

Tags




Discuss