1553 - I2P18_EECS_Assignment_7 Scoreboard

Time

2018/12/05 08:54:00 2018/12/05 08:55:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10845 Light Reflection
10852 Simple Addition
11219 Get your array and then sort it!

10845 - Light Reflection   

Description

Consider a room of size H*W (3<=H,3<=W) in which its four walls are covered by mirrors. You need to simulate the light reflection in the room and print out the k-th reflection point.

We assume that the light is always emitted from the left mirror and moves in the upper-right direction at an angle of 45 degrees. More specifically, the starting point can be represented by (r, 1) where 1<r<H. The light will stop if it hits any corner of the room . 
 

For example, if the room size is 5*6 and the light starts at (3,1), then the first point it hits is (3,1), the second point is (1,3), the third point is (4,6), and so on. If k=3 you need to print out (4,6).

If the light hits a corner before the k-th reflection, you need to print out coordinate of that corner. For example, if k =10 and the first point is (3,1), you need to print out (1,1) because the light stops at (1,1).

Input

The first line is the height and width of the room.

The second line is the starting point (the first reflection point).

The third line is k, which means you need to print out the k-th reflection point.

Output

The coordinate of the k-th reflection point.

Note that you DO NOT need to print a newline character ‘\n’ at the end of the output.

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




11219 - Get your array and then sort it!   

Description

[Partial Judge]

Given a sequence of integers, sort it in increasing order by implementing the function my_sort().

The main code and the header code are provided as below.

There are two functions defined in the header file:

  • int* readInput();
  • void my_sort(int* B);

Function int* readInput() is given. It will read the input numbers, save it into an array, say Seq, and finally return the address of the array.
The first element of array Seq is the number of integers to be sorted. The following elements are the integers.

Function void my_sort(int* B) is the one leaved for you to implement. It take in a single argument B of type int*, whose value is the address of the address of the array Seq.

* Note that the address of the array Seq is returned by the function int* readInput().
* Also, you should be care of the actual type of the variable you want to access to. Do not be confused with the function definition.
* When submitting your code, remember to set Language option to "C: -O2 -lm -std=c99"

Input

A line of N integers seperated by a space in between.

100 <= N <= 1000.

The value of integer falls in the range of [-1000, 1000].

Input is handled by the provided function int* readInput(). You don't need to worry about it.

Output

A line of sorted integers seperated by a space in between. No extra space after the last integer. An newline character ('\n') is appended at the end.

You don't need to worry about it. It is handled in the provided main function.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11219.c

Partial Judge Header

11219.h

Tags




Discuss