1318 - I2P(I)2017_Chen_Hw3 Scoreboard

Time

2017/11/02 15:30:00 2017/11/13 15:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11195 Hanoi
11649 World of Tanks
11656 Simple Permutation

11195 - Hanoi   

Description

The Tower of Hanoi is a mathematical game puzzle. It consists of three rods, which are A, B and C. The puzzle starts with disks in ascending order of size on rod A, the smallest at the top.

The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules:

1.   Only one disk can be moved at a time.

2.   Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack.

3.   No disk may be placed on top of a smaller disk.

Write a program to simulate the moves of the disks. Print the number of disk which is moved in each step.

 

For example, if n = 3, the moves of each steps are:

move disk 1 from rod A to rod C
move disk 2 from rod A to rod B
move disk 1 from rod C to rod B
move disk 3 from rod A to rod C
move disk 1 from rod B to rod A
move disk 2 from rod B to rod C
move disk 1 from rod A to rod C


You should print out:

1
2
1
3
1
2
1

The following graph is an easy example when n = 3:

 「hanoi tower」的圖片搜尋結果

You only need to complete following function:

#include <stdio.h>
#include "function.h"
void hanoi(int n, char A, char B, char C)
{
    // Write your code here
}

You may refer to [11656 Simple Permutation] for the submission specifications.

Input

An integer n (0<n<20), which means the number of disk.

Output

Print out the number of disk which is moved in each step, and there is a '\n' at the end of each line.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11195.cpp

Partial Judge Header

11195.h

Tags




Discuss




11649 - World of Tanks   

Description

Copyright © I2P_EECS_MID1_1 

Now you are in the World of Tanks !!!

 

Your mission is to follow the instructions and pick the coins : )

You will get a map of the world like this:

               

 

 is your tank with size 3x3(xox is the head of the tank), and $ represents a coin, # represents the wall, ^ represents the hill.

If you tank (3x3 body) is above the $, you will pick it up($ can't be counted again). If # or ^ is in front of the tank(in front of the xox, tank's front part), you can not move. Coins' position don't overlap initial tank's position.

The tank has four forward directions(South, East, North, West). Its direction is where xox heads. Notice that the upper of the map is the North, and the initial direction of tank is not always North.

And you will receive a sequence of instructions, which contains (takes a step along the tank's head direction), R(tank's head turns right), and L(tank's head turns left). Instructions like R and L only change tank's head direction, and don't affect tank's position(would not cause moving). 

Your mission is to receive the instructions and dirves the tanks in order to collect coins, and report the amount of coins you get in the end.

Notice: The sample input in the below seems not aligned because the size of each character is not identical. You can see the map above(it is the same as sample input) if you want to see clearly. 

 

There are sample codes for you:

#include <stdio.h>
#include <string.h>

#define EAST 0
#define SOUTH 1
#define WEST 2
#define NORTH 3

char map[100][100];
char actions[100]={};
int coin_amount = 0;

// tank's initial direction
char init_dir;
// tank's direction now
int dir_now;
// tank's center x and y
int center_x, center_y;

void decide_initial_direction()
{
    /// Decide tank's initial direction
    /// Using init_dir
    /// To determine dir_now

 

}

void take_a_step()
{
    if (dir_now == NORTH){
        /// Detect wall first
        if ( ??? ){

        }
        /// And then detect hill
        else if (( ??? )) {

        }
        /// If there is no obstacle, take a step
        else {

        }
    }
    else if (dir_now == SOUTH){

    }
    else if (dir_now == EAST){

    }
    else if (dir_now == WEST){

    }
}

void pick_the_coins()
{
    int j, k;
    for (j = center_x - 1; j <= center_x + 1; j++){
        for (k = center_y - 1; k <= center_y + 1; k++){
            /// determine whether there are coins under the tank

 

        }
    }
}

void turn_right()
{
    /// Change direction depending on dir_now
}

 

void turn_left()
{
    /// Change direction depending on dir_now
}

int main()
{
    int i, j, k, rows, cols;
    int actions_number;
    int component = 0;

    /// Raed problem's input
    scanf("%d %d %d %c", &rows, &cols, &actions_number, &init_dir);
    while (getchar() != '\n');
    for (i = 0; i < actions_number; i++){
        scanf("%c", &actions[i]);
    }

    /// Read map
    for (i = 1; i <= rows; i++){
        while (getchar() != '\n');
        for (j = 1; j <= cols; j++){
            scanf("%c", &map[i][j]);
            /// Find tank's center x and y
            if (((map[i][j]) == 'x') || ((map[i][j]) == 'o') || ((map[i][j]) == 'O')){
                component++;
                if (component == 5){
                    center_x = i;
                    center_y = j;
                }
            }
        }
    }

    decide_initial_direction();

    for (i = 0; i < actions_number; i++){
        if (actions[i] == 'F'){
            take_a_step();
            pick_the_coins();
        }
        else{
            if (actions[i] == 'R'){
                turn_right();
            }
            if (actions[i] == 'L'){
                turn_left();
            }
        }
    }

    printf("%d\n", coin_amount);

    return 0;
}

 

 

Input

The first line of the input contains four things: 

1. The rows of the map (0 < rows < 100)

2. The columns of the map (0 < cols < 100)

3. The total length of instructions (0 < instructions's length < 100)

4. The initial tank's direction(N, E, S, T)

The second line is the content of instructions.

For the next lines, they illustrate the map.

Output

The number of coins you get. (printf "\n" in the end)

Sample Input  Download

Sample Output  Download

Tags




Discuss




11656 - Simple Permutation   

Description

Writers : jjjjj19980806 & pclightyear

Given an integer n, please output a sequence of integers as described below :

(1) The sequence consists of 2n – 1 integers.

(2) Output format : 1 2 … n-1 n n-1 … 2 1

(3) There is a whitespace behind each integer except for the last number.

(4) Remember to output '\n' after you print out your answer.

Note :

(1) This is a partial judge problem. Make sure to download partial judge code and partial judge header we give to you. Before you submit your code, your code should be compiled successfully on your computer. (If you run into any trouble, feel free to ask on ilms.)

(2) These keywords should not appear in your submission : for, while, goto. (i.e. you can’t use any loopotherwise your will receive compiler error.)

(3) You can’t declare any global variable and function except for “print()” (which is declared in the header file we give to you) in your code.

(4) You need to choose C Language instead of C++.

(5) Your submission will look like :

 

#include <stdio.h>

#include "function.h"

// Not "11656.h" !!

void print(int level, int n){

    // add your code here!

}

 

Input

There is only one integer n in the input file.

  • 1 ≤ n ≤ 10

Output

As described above.

You can find out more information in sample output.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11656.c

Partial Judge Header

11656.h

Tags




Discuss