2212 - I2P(I)2020_Hu_mid2 Scoreboard

Time

2020/12/14 18:30:00 2020/12/14 21:30:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
12448 Hu_cheatsheet
13018 Diagonally sorting
13020 Happy B to As with Weeheehea
13021 Longest Binary Distance

12448 - Hu_cheatsheet   

Description

printf() and  scanf() format

printf("%d", n);
 

FORMAT  ARGUMENT TYPE

%d, %i  int           decimal

%lld    long long

%llu    unsigned long long

%u      unsigned int

%x      unsigned int  hexadecimal

%#x     unsigned int  hexadecimal with prefix 0x

%f      double  

%Lf     long double

%c      char         to print a character

%s      char *      string (character array ended with '\0')


scanf("%d", &n);
 

FORMAT  ARGUMENT TYPE

%d      int *       &n, store the input integer in n

%ld     long *

%lld    long long *

%u      unsigned int *

%f      float *     read float

%lf     double *    read double

%Lf     long double *   read long double

%c      char *      read 3 characters %3c

%s      char *      read a string until whitespace

%n      int *       with %s, to get string length

                   char a[100]; int len; 
                 scanf("%s%n", a, &len);
                 len
 will have the string length

 

Frequently used functions

#include <string.h>
char str[10];
scanf("%s", str);
to get the string length using strlen(str)

#include <ctype.h>
isspace(ch), islower(ch), isupper(ch), isdigit(ch)
isalpha(ch), toupper(ch), tolower(ch)

To create 5-by-5 two-dimensional array, we need to write

int a[5][5];

 

It will be indexed as follows:

 

 a[0][0] 

 a[0][1]

 a[0][2]

 a[0][3]

 a[0][4]

 a[1][0]

 a[1][1]

 a[1][2]

 a[1][3]

 a[1][4]

 a[2][0]

 a[2][1]

 a[2][2]

 a[2][3]

 a[2][4]

 a[3][0]

 a[3][1]

 a[3][2]

 a[3][3]

 a[3][4]

 a[4][0]

 a[4][1]

 a[4][2]

 a[4][3]

 a[4][4]

 


 

 


How to read the following data?
1 2 3 4 5 e
#include <stdio.h>

int main(void)
{
    int x;
    while (scanf("%d", &x) == 1) {  
     
printf("x=%d\n", x);
    }
    return 0;
}

How to read the following data?

2

L 5 2
D 5 3

#include <stdio.h>

int main(void)

{

   char ch;
   int i, n, row, col;

   scanf("%d", &n);

   for (i=0; i<n; i++) {

      while(getchar()!='\n');

      scanf("%c%d%d", &ch, &row, &col);

   }

   return 0;

}

 

Using for loops to print a two-dimensional array

   for(i = 0; i < row; i++) {
      for (j = 0; j < col; j++) {
         printf("%5d", A[i][j]);
      }
      printf("\n");
   } 

logical and comparison operators operators:
!    &&    ||    ==     !=    >   <     >=    <=

arithmetic operators:

+    -    *    /    %

bitwise operators:

&    |    ^    <<    >>    ~

int strcmp(const char *lhs, const char *rhs);

int strcat(const char *lhs, const char *rhs);

int strcpy(const char *lhs, const char *rhs);

How to avoid common errors and how to debug for OJ

1. Put the arrays in the 'global' area. Set their size bigger than required. Avoid using variable-length arrays (e.g. int arr[n];). Keep the array size fix (e.g., int arr[1000];).

2. After writing the code for reading input data, you may print out the data to check if your code reads them correctly. Do not proceed to write subsequent code before you confirm that.

3. If your program crashes, usually it is caused by memory related errors. Check the ranges of for-loops to see if your code attempts to read or write the elements out of the arrays' boundary.

Note : If you are using visual studio, add #pragma warning(disable:4996) in the first line so that you can use scanf on your local machine.

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss




13018 - Diagonally sorting   

Description

Given a NxM array, please sort each diagonal line in ascending order from top-left to bottom-right.

 

For example, given 4x4 array, you should sort these diagonal lines:

This problem is partial judge, you need to implement the function:

// Sort each diagonal line of arr (which size is row x col)

void array2d_sort(int row, int col, long long arr[][500]);

 

Input

The first line contains two integers, N, M. 

The next N lines contain the array, each element in the array is separated by a space.

1 ≤ N, M ≤ 500

-1010 ≤ element in the array ≤ 1010

 

Output

Output the diagonally sorted array, with each element in the array separated by a space, and print out a newline after each row.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13018.c

Partial Judge Header

13018.h

Tags




Discuss




13020 - Happy B to As with Weeheehea   

Description

Let's call a grid 8-puzzle board if the gridsize is 3 x 3 and there is exactly one cell is 'x' and others are '1' or '0'.

In one operation, you can exchange the 'x' cell of a 8-puzzle board with any cell which is adjacent to the 'x' cell. The cell (ij) is adjacent to the cell (i-1j), (ij-1), (ij+1) and (i+1j) (if not out of bounds).

Now you are given N + 1 8-puzzle boards A1A2, ..., AN and B. You need to answer how many 8-puzzle boards of A1A2, ..., AN could be made into B in at most K operations.

Sample Explanation

Here are the N + 1 8-puzzle boards A1A2, ..., AN and B of sample, where N = 4, K = 2.

0 x 0     0 0 0     0 0 0     0 0 1     0 x 0

 1 0 1     1 x 1     0 1 1     1 0 x     1 0 1 

0 0 1     0 0 1     x 0 1     0 0 1     0 0 1

A1        A2        A3        A4        B

A1A2 and Acould be made into B in K operations. The following show some feasible way to make them into B.

A way to make A1 into B in K operations:

x 0

1 0 1

0 0 1

A1 is as same as B in the beginning

A way to make A2 into B in K operations:

0 0 0           0 x 0

1 x 1 ========> 1 0 1

0 0 1           0 0 1

                exchange (1,2)

A way to make A4 into B in K operations:

0 0 1           0 0 x           0 x 0

1 0 x ========> 1 0 1 ========> 1 0 1

0 0 1           0 0 1           0 0 1

                exchange (1,3)  exchange (1,2)

Input

The first line contains two integers N and K – the number of 8-puzzle boards in A and the maximum number of operations you can execute for each 8-puzzle board.

Then you are given A1A2, ..., AN and B in the order. All of them are in 3 lines of 3 characters. Please refer to Sample Input.

 

It's guaranteed that:

  • For testcase 1~6: 1 ≤ N ≤ 10, 0 ≤ K ≤ 7
  • For testcase 7:     1 ≤ N ≤ 105, 0 ≤ K ≤ 7
  • For testcase 8:     1 ≤ N ≤ 105, 0 ≤ K ≤ 10

To pass testcase 7 and 8, note the efficiency of your strategy(code). It may be a little hard, so maybe you can try to solve other problems first after you pass first six testcases.

Output

Output how many 8-puzzle boards of A1A2, ..., AN could be made into B in K operations and then print a newline('\n').

Sample Input  Download

Sample Output  Download

Tags




Discuss




13021 - Longest Binary Distance   

Description

Binary distance for an integer is the number of "0" between two adjoining "1"s in the binary representation of an integer. For example, the binary representation of 37 is 1001012, so 37 has two binary distances which are 2 and 1.

If there aren't any "0"s between two adjoining "1"s, the binay distance will be 0. e.g. 7 (1112) has two binary distances = 0.

If the number of "1" in the binary representation is less than 2, the binay distance will be -1. e.g. 8(10002) only has one binary distances = -1.

In this problem, you are asked to compute the longest binary distances for the given q integers.

For example, if the input integer is 37, you should output 2 as the answer.

Input

First line countains an integer which denotes q. (1 ≤ q ≤ 20)

Then, q lines follow.

Each line contains one integer N (0 ≤ N ≤ 263 - 1).

Output

Output contains q lines and each line contain the longest binary distance of the input integer ended with '\n'. 

Sample Input  Download

Sample Output  Download

Tags




Discuss