1352 - I2P (I) 2017_Yang_hw_p2 Scoreboard

Time

2017/11/30 20:00:00 2017/12/11 23:59:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11240 license
11241 Simple Addition
11701 Friend
11703 N-Rings
11704 Deliver gifts
11712 Morse code

11240 - license   

Description

There are N license. Each license has four-digit integer, each integer between 1 to 9. For example, if N=7, the input may look like

7

1324

5566

3578

4123

5656

4312

9847

We want to get the licenses that use the same digits and the digits should be sorted from small to large. For example, 1324, 4123, and 4312 are the combination of the same digits (1, 2, 3, and 4). We want to get 1234. Similarly, 5566 and 5656 are the combination of the same digits (5, 5, 6, and 6). We want to get 5566. 

For output, we list the modified licenses in an increasing order line by line, so the output will look 

1234

5566

 

<Hint>

You may consider the following algorithm:

0. Create a character array (char str[5];) for storing the input integers and create an array which is initialed to zero (int HIT[10000];) to record the occurrences of input integers.

1. Read the number of input integers and store it in variable N (scanf("%d", &N);).

2. For each of the next N integers, do 

    2.1 Read the four-digit integer and store it as a four-character string in str.

    2.2 Use the bubble sort algorithm to rearrange the four characters.

    2.3 Convert the rearranged string to an integer m and increase the value of the corresponding element of the HIT array by 1 (HIT[m]++;).

3. Check each element of the HIT array; if its value is larger than 2, print the corresponding integer.

 

The bubble sort algorithm:

/* Using bubble sort to rearrange an array A[n] */

for (i = n; i > 0; i--) {

   for (j = 1; j < i; j++) {

      if (A[j-1] > A[j]) {

         /* swap A[j-1] A[j] */

      }

   }

}

Input

The first line contains a number N (1<=N<=100).

The next N lines provide the N four-digit integers.

Output

Each line shows a modified unique integer as explained in the problem description.

Remember to print a newline at the end of each line.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11241 - 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

You will be provided with the following sample code, and asked to implement function "addition".

#include <stdio.h>

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

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];

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

    return 0;
}

int addition(int* ptr_a, int array_num, int* entry[], int* index_to_add, int num_ind){
    /*your code*/
}

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

Tags




Discuss




11701 - Friend   

Description

There are 2002 persons. Now we want to investigate the relationship between them. We choose N persons for investigation, and their numbers are from 0 to N-1. Next, we will investigate the relationship between any two given persons. Assume that if person a and person b are friends, the friends of person a and the friends of person b will also be friends.

 

We provide with the following partial code and ask you to complete get_ga, get_gb, and set_friend_ab functions:

#include<stdio.h>
#include<stdbool.h>
#define MAXN 2005

bool f[MAXN][MAXN];
int n;

void init(){
      int i=0,j;
      for(;i<n;++i){
            for(j=0;j<n;++j){
                  f[i][j]=false;
            }
            f[i][i]=true;
      }
}

bool is_friend(int a,int b){
      //if f[a][b]=true, person a and person b are friends.
      return f[a][b];
}

int ga[MAXN],gb[MAXN];
int len_ga,len_gb;

void get_ga(int a){
      //Array ga saves all the friends of person a.
      //For example, if all the friends of person a are 1, 4, 5 and 10,
      //ga[]={1,4,5,10}, len_ga=4.
      //Please think how to get Array ga according to 2D Array f.
}

void get_gb(int b){
      //Array gb saves all the friends of person b.
      //Similar to get_ga().
}

void set_friend_ab(){
      //Now you have Array ga and gb.
      //Because person a and b will be friends,
      //how to use Array ga and gb for updating 2D Array f?
}

void merge_friend(int a,int b){
      if(is_friend(a,b)) return;
      get_ga(a);
      get_gb(b);
      set_friend_ab();
}

int main(){
      int t,q;
      scanf("%d",&t);
      while(t--){
            scanf("%d%d",&n,&q);
            init();
            while(q--){
                  int op,a,b;
                  scanf("%d%d%d",&op,&a,&b);
                  if(op==1) puts(is_friend(a,b) ? "they are friends!" : "they are not friends!");
                  else merge_friend(a,b);
            }
      }
      return 0;
}

Input

There is a number t in the first line, indicating that there are t test cases. Next, there are two numbers, N and Q, in each test case, indicating that we will investigate N persons, followed by Q instructions. Every instruction consists of 3 numbers, P, a and b. If P=0, it shows that person a and person b are friends. If P=1, we have to judge whether person a and person b are friends according to the given information.

Notice that:

(1) 0<=a,b<N

(2) a!=b

(3) 0<Q<=10^5

(4) 0<N<=2000

Output

For every instruction P=1, if a and b are friends, please print "they are friends!". If they are not, print "they are not friends!". Remember to add '\n' in the end of every output.

Sample Input  Download

Sample Output  Download

Tags

題目有瑕疵 若a,b為朋友,他們朋友們也互朋友,這句 話嚴格來說要遞迴套用他們朋友們的朋友們 此題並非此意



Discuss




11703 - N-Rings   

Description

N-Ring is a game, in which N rings are put on a stick in order, and every rings are effected by each other following the rules below:

  1. The first ring can be put on and taken off at any time.
  2. If you want to put on or take off the N-th ring, you have to put on the (N-1)-th ring, and take off all the rings from 1 to (N-2)-th. By doing so, you can put on or take off the N-th ring.

Our goal is to take off all the rings.

Hint: You can implement the following code we provided

#include<stdio.h>

void in(int);

void out(int n){

    // take off the first n rings

}

void in(int n){

    //put on the first n rings

}

int n;

int main(){

    scanf("%d",&n);

    out(n);

    return 0;

}

Input

Given an integer N, 1 <= N <= 18, meaning there are N rings.

Output

Output the answer of N-Rings in order.

“Move ring n out” means taking the n-th ring off the stick.

“Move ring n in” means putting the n-th ring on the stick.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11704 - Deliver gifts   

Description

A teacher is going to deliver N gifts to N students in the class. Every student can get exactly one gift. Since the value of each gift is different, the teacher decides to deliver the gifts based on student ranks. Thus, he evaluates each gift with a value T, which means only the students who rank higher than or equal to T are allowed to receive that gift. You are asked to write a program counting how many ways there are for the teacher to deliver those gifts.

 

For example, there are 3 students in the class (N=3), and the 3 gifts are valued as 2, 3, 3. So there are 4 different ways to deliver those gifts: {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, where a solution {a, b, c} means the first gift (with value 2) is delivered to the student with rank a, the second gift (with value 3) is delivered to the student with rank b, and the last gift (with value 3) is delivered to the student with rank c.

P.S. The problem is from 2015 網際網路程式設計全國大賽

Input

The first line contains a positive integer N.

The second line consists of N positive integers, indicating the value Ti of the N gifts.

1 ≤ N ≤ 20

1 ≤ Ti ≤ N

Output

Please output an integer, indicating how many ways there are to deliver those gifts.

Sample Input  Download

Sample Output  Download

Tags




Discuss




11712 - Morse code   

Description

Morse code is a way to represent English letters (here we only consider capital letters). The code is composed of some long signals and some short signals. For convenience, we represent a long signal as '-' and represent a short signal as '*'. Then ‘/’ is used to serve as a blank that distinguishes each word that consists of several letters.

For example, ''NPSC GG'' is ''-* *--* *** -*-* / --* --*", where  “-*” = N and “*--*” = P, and the code for other letters is shown below. 

However, these long and short signals in the Morse code cannot be represented using gesture. A way to simulate the long and short signals is as follows:

  1. “===” represents a long signal. (hitting table for 3 times)
  2. “=” represents a short signal. (hitting table for 1 time)
  3. For a letter, “.” is used as a pause to separate signals.
  4. In a word, “…” is used as a pause to separate letters.
  5. “…….” is used to separate words (that is, to represent ‘/’ as mentioned above).

       

For example, “NPSC GG" can be encoded as follows:

P.S  the problem is from 2015 網際網路程式設計全國大賽

Input

There are two lines. The first line is an integer N, meaning the second line will give a string with length N, and this string is only composed of '=' and '.'.

.N <= 999.

.The output string begins and ends with a non-blank letter.

Output

Print the result after decoding

Following is a sample test case:

Input:

57
=.===...===.=.=.=...===.=.===.=...===.=.=...=...=.=.===.=

Output:

ABCDEF

 

Sample Input  Download

Sample Output  Download

Tags




Discuss