1323 - I2P(I)2017_Chen_Lab3 Scoreboard

Time

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

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11657 Rabbit population
11661 Prophetic dream
11665 World war

11657 - Rabbit population   

Description

In the West, Leonardo of Pisa, a mathemetic scientists, considers the growth of an idealized (biologically unrealistic) rabbit population, assuming that:

  1. a single newly born pair of rabbits (one male, one female) are put in a field;
  2. rabbits are able to mate at the age of one month so that at the end of its second month a female can produce another pair of rabbits;
  3. rabbits never die and a mating pair always produces one new pair (one male, one female) every month from the second month on.

The puzzle is that: how many pairs will there be in any specific month?

 

You can't use loops in ths problem

You need to implement following function:

#include <stdio.h>
#include "function.h"
int Rabbit(int month)
{
    // Write your code here
}

Input

The specific month N 

Output

Total pairs of rabbits 

Sample Input  Download

Sample Output  Download

Partial Judge Code

11657.c

Partial Judge Header

11657.h

Tags




Discuss




11661 - Prophetic dream   

Description

''In a prophetic dream(預知夢), you can see your future. It is difficult to determine whether a dream is prophetic because we can't confirm until the vision happens. Even then, we only heard of stories . There are so many other dreams that do not come true. Thus, prophetic dream may just be mere coincidences. ''

Whether the prophetic dream exists or not, there are many dramas and movies based on it. Recently, While you were sleeping, the famous 2017 Korean TV series starred by Lee Jong-suk and Bae Suzy is majorly featuring prophetic dreams. In the story, Suzy has prophetic dreams. One day, she had a dream about tomorrow lottery numbers. However, she didn't see the last number in her dream. She only remember that the last number is maximum in lots of other numbers in her dream. Thus, your mission is to help her find the maximum element in a given array with a given size of array. Since you're a professional software engineer, you must use recursion method to solve the problem (cannot use loops to solve).

 

You need to implement following function:

#include <stdio.h>
#include "function.h"
int maxElement(int arr[], int n)
{
    // Write your code here
}

Input

first line : array size N (0<N<20)

second line: N elements in array

Output

Maximum element in array

Sample Input  Download

Sample Output  Download

Partial Judge Code

11661.c

Partial Judge Header

11661.h

Tags




Discuss




11665 - World war   

Description

Country H upgrades the tank in order to defeat Country T in world war. 

You're a soldier in great Country H and have received secret tasks : Collect the military secrets related to Country T

 

You wil get a map of Country T like this:

              

 is your tank with size 3x3 (xox is the head of the tank). 

'$' represents a military secrets,  '#' represents the wall, '^' represents the hill.

If you tank (3x3 body) is overlaped with 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. Military secrets' position don't appear at 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). 

 

Since the tank is upgraded, the tank can now execute instruction J (takes two step along the tanks head direction). However, you should NOT execute J when the tank may collides with hill or wall (in this case, you pick up nothing, and stand still at the original position).

 

Your will collect the military secrets within the valid instruction as many as possible. Then report the number of it to your boss, HT, immediately !

Fighting ! 

 

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 (  ){

           /* TODO : Implement the instruction "J" here */

       }         
        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, S, E, W)

The second line is the content of instructions.

For the next lines, they illustrate the map.

Output

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

Sample Input  Download

Sample Output  Download

Tags




Discuss