1564 - I2P18_EECS_Lab_5_Make_up Scoreboard

Time

2018/12/17 08:10:00 2018/12/17 09:50:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10308 2048
10852 Simple Addition
11611 Addition and Division of Big Number

10308 - 2048   

Description

The game of 2048 is very simple. Given a 4x4 map containing tiles and spaces. The values are displayed on the tiles, and the spaces are displayed as 0. The values of tiles are always the power of 2. For example,
    2    2   64  128
    4    0    4   16
    4    4    4    4
    0    0    2    0

is a valid map.

We are able to slide the tiles in the only down direction. The rules of sliding are defined as follows:
1. All tiles slide past spaces. If you move the puzzle to the bottom, all spaces will end up on the top.
2. After sliding to collapse spaces, any tiles with the same value combine and the remainder of the column slides to fill in the hole.
3. One tile can only combine(be combined) once.
4. The combination always starts from the bottom.
5. Contrary to the famous game of 2048, there are no new tiles generated.

For instance, if we have the map above, after we slide the tiles once, the map becomes
    0    0    0    0
    0    0   64  128
    2    2    8   16
    8    4    2    4


Your job is to output the number of spaces for each column after sliding the tiles.

Hint:

#include <stdio.h>

#define WIDTH 4
#define HEIGHT 4

int map[HEIGHT][WIDTH];

void collapse(){
    /* your code here */
}

void slide(){
    /* your code here */
}

void show(){
    /* your code here */
}

int main()
{
    int N, d;
    int i, j;

    scanf("%d", &N);
    for(i = 0; i < HEIGHT; i++){
        for(j = 0; j < WIDTH; j++){
            scanf("%d", &map[i][j]);
        }
    }

    for(i = 0; i < N; i++){
        slide();
    }

    show();

    return 0;
}

Input

N (the count of slides)
The map

Output

The number of spaces of each column

Use "%d " to print each number. Print a newline '\n' at the end.
Note that the value of tiles will not exceed 8192.

Sample Input  Download

Sample Output  Download

Tags




Discuss




10852 - Simple Addition   

Description

Four arrays A, B, C and D with size MxN. B, C, D are stored in an array of pointers, and A is stored in a separated array. The task is to add the designated elements of A and the corresponding element from a chosen array of B, C, D, and output the result.

 

Take sample input as an example. Size of the arrays are 3 rows by 2 columns, initial values are as the form below. Input number “2” in the sixth line indicates D is chosen array and we want the sum of elements with two indices (1,0), (2,0)

Therefore, the answer is A(1,0)+D(1,0)+A(2,0)+D(2,0)=2+8+4+10=24

Note that

1.      This problem involves three files.

  • function.h: Function definition of addition.
  • function.c: Function describe of addition.
  • main.c: A driver program to test your implementation.

You will be provided with main.c and function.h, and asked to implement function.c.

2.     For OJ submission:

       Step 1. Submit only your function.c into the submission block. (Please choose c compiler) 

       Step 2. Check the results and debug your program if necessary.

3.     If the same index appears n times, just add the values n times.

main.c

#include <stdio.h>

#include ”function.h”

int main(void) {

  int a[50][50], b[50][50], c[50][50], d[50][50];

  int index_to_add[20];

  int *entry[3];

  int i, j, m, n, array_num, num_ind;


  scanf("%d %d", &m, &n);


  for(i=0; i<m; i++)

    for(j=0; j<n; j++)

      scanf(“%d”, &a[i][j]);

  for(i=0; i<m; i++)

    for(j=0; j<n; j++)

      scanf(“%d”, &b[i][j]);

  for(i=0; i<m; i++)

    for(j=0; j<n; j++)

      scanf(“%d”, &c[i][j]);

  for(i=0; i<m; i++)

    for(j=0; j<n; j++)

      scanf(“%d”, &d[i][j]);

  scanf("%d", &array_num);

  scanf("%d", &num_ind);

  for(i=0; i<num_ind*2; i=i+2)

    scanf("%d %d", &index_to_add[i], &index_to_add[i+1]);


  entry[0] = &b[0][0];

  entry[1] = &c[0][0];

  entry[2] = &d[0][0];


  /*

    &a[0][0]: Address of A’s first element

    array_num: Index of chosen array. 0: B, 1:C, 2:D.

    entry: An array of pointers, stores {&b[0][0], &c[0][0], &d[0][0]}

    index_to_add: Locations to be summed. Value would be {1,0,2,0,…} in sample case.

    num_ind: Number of locations to be summed.

  */

  printf("%d\n", addition(&a[0][0], array_num, entry, index_to_add, num_ind));


  return 0;

}

function.h

#ifndef FUNCTION_H

#define FUNCTION_H

int addition(int*, int, int*[], int*, int);

#endif

Input

The first line is the size of arrays, M rows by N columns. The following four lines are initial values arranged by row major. The sixth line tells B, C or D is chose. The next line is the number of elements k to be summed. And the last k lines are the row and column indices of elements to be add. 0 < M, N < 50. 0 < k < 10. Index starts from 0.

Output

An integer, sum of desired elements.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10852.c

Partial Judge Header

10852.h

Tags




Discuss




11611 - Addition and Division of Big Number   

Description

As we all know, all kinds of data type like int, long, etc have their limitation in representing numbers. 

For instance, if we use int to store some variable, it may not contain the value we want if the variable is bigger than 231, which is roughly the same as 2 * 109.

So it would get into trouble if we want to calculate some very large number, like 101000 + 1.

In this task, you are asked to implement a calculator that can make some simple calculation of big number possible.

For simplifying the question, we will give you several data groups containing two big numbers a and b, and a integer divisor c.  For each group, all we need is the integer part of (a + b)/c.

Hint: 

You can recall the very first experiment you learned addition. At that time the teacher may tell you that you should calculate the addition in each digit , only maintain the very right digit as the answer and send the others as the carry to the next digit. For instance, if we want to calculate 999 + 999, the following method might be well:

   9  9  9

   9  9  9

           +

-------

   8  8  8 (right most digit)

1  1  1      (carry)

           +

--------

1  9  9  8

You may use int array to record the big number and the upper method to calculate.

 

For division, you can also use some likely method.

We do the division from the very left digit of dividend(被除數) , calculate the result and pass the reminder to the right digit.

For instance, if we want to calculate 199 / 2:

             9    9

    ——————

2 )1     9     9

      1     8

   ————————

             1      9

             1      8

   ————————

                    1    

Characters in red are reminders.

 

Other better method is encouraged.

 

 

Input

The input contains several lines.

The very first line is a integer N representing the total times of calculation. (1 <= N < 50)

From the second line to the last line, each three lines forms a group representing a calculation. 

The first line and the second line of each group are two numbers, which are in decimal, bigger than or equal to 0 and smaller than 101000. For making the question easier, the lengths of the two numers are just the same. It is possibe for the numbers beginning with 0.

The third line of each group is the divisor (bigger than 0 and smaller than 231-1).

Output

The answer of each group.

Please do not pad 0 in your answer. Eg 87 is a legel answer but 087 is illegal.

You should add a newline at the end of the answer.

Sample Input  Download

Sample Output  Download

Tags




Discuss