1791 - I2P(I)2019_Yang_CS_Mid1 Scoreboard

Time

2019/10/22 18:40:00 2019/10/22 21:10:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
11654 yang_cheatsheet
12441 Palindrome
12446 Bacteria Widespread
12447 How Much Bateria (Original)

11654 - yang_cheatsheet   

Description

printf() and  scanf() format

printf("%d", n);
 

FORMAT  ARGUMENT TYPE

%d, %i  int           decimal

%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");
   } 

operators:
!   &&    ||    ==     !=    +    -    *    /    %
>   <     >=    <=

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.

 

Input

Output

Sample Input  Download

Sample Output  Download

Tags




Discuss




12441 - Palindrome   

Description

Palindrome is a string that is identical to its reverse, like "level" or "aba".  Check whether a given string is a palindrome or not.

Input

The input consists of multiple lines. Each line contains a string. The length of each string is less than 100000.  The number of test case is less than 1000.

Output

For each test case, output "Yes" if it's a palindrome or "No" if it's not a palindrome in a line.

 

Sample Input  Download

Sample Output  Download

Tags




Discuss




12446 - Bacteria Widespread   

Description

Hey, can I say somthing amazing?  Bacteria touched the air for some reason and begin to widespread in the classroom. The bacteria turned out to be Firmicutes (some kind of bacteria). The classroom can be viewed as a 2D grid map with size R x C. Walls in classroom are denoted as #, clean areas not polluted by Firmicutes are denoted as C, and places where there exist Firmicutes are denoted as F. The classroom is guaranteed to be surrounded by walls. For example a classroom of size 7 x 8 with some area polluted may look like this :

 ########
 #CCC#CC#
 #CFC####
 #CCCCCC#
 #CC#####
 #FCCCCC#
 ########

Firmicutes reproduces rapidly. Initially, some areas in the classroom are polluted by Firmicutes. For every second, if an area is polluted by Firmicutes, the Firmicutes on this area will reproduce themselves and spread to neighboring clean areas. Here, we define neighboring areas of area (r, c) are (r+1, c)(r-1, c)(r, c+1), and (r, c-1). Note that Firmicutes cannot spread onto walls, which means that even if a wall is neighbor to some polluted area, the wall will not be polluted. The following example is a classroom from t = 0 ~ 2 seconds.

Initially, t=0. Some areas are polluted.

 ########
 #CCC#CC#
 #CFC####
 #CCCCCC#
 #CC#####
 #FCCCCC#
 ########

When t=1,

 ########
 #CFC#CC#
 #FFF####
 #CFCCCC#
 #FC#####
 #FFCCCC#
 ########

When t=2,

 ########
 #FFF#CC#
 #FFF####
 #FFFCCC#
 #FF#####
 #FFFCCC#
 ########

Given how the class looks like initially (when t=0) and a time T, please output how the classroom looks like when t=T.

Input

The first line consist of three integers R, C, T, meaning the size of the classroom and a time.

For the following R lines, each line has C characters, being how the classroom looks like initially. Each character will be one of {#CF} and the classroom is surrounded by walls (#).

Technical Restrictions

  • 3 ≦ R, C ≦ 100

  • 0 ≦ T ≦ 100

  • The first test case is same as sample IO. It is suggest to use it to check whether your output format is valid.

Output

Please output how the classroom looks like in the T-th second (when t=T).

Sample Input  Download

Sample Output  Download

Tags




Discuss




12447 - How Much Bateria (Original)   

Description

Hey, can I say something amazing? Culturing bacteria is forbidden at school. Your Petri dish(培養皿) will be forfeited if caught by the teachers.

The Petri dishes are placed on the table in a row. Each Petri dish contains a kind of bacteria, labeled with an integer. Two bacteria of the same species will be labeled with the same integer, while two bacteria with different species will be labeled with different integers.

The teacher wants to know that how many species of bacteria he will get if he forfeits the within some range of the table. Given the number of Petri dish N and their species s0, s1, ..., sN-1, the teacher gave you Q queries. For each query, the teacher gave you two integer L and R. You have answer how many species of bacteria there are in range sL, ..., sR.

Input

There are two integers NQ, begin the number of Petri dish and the number of queries.

The second line are N integers s0, s1, ..., sN-1, being the species of the bacteria.

The following Q lines are queries. Each query occupies a line and contains two integers L and R.

Technical Restrictions

  • 1 ≦ N ≦ 1000000

  • 1 ≦ Q ≦ 1000000

  • 0 ≦ si ≦ 31

  • 0 ≦ L ≦ R < N

Test Case Info

  1. For the first test case, it is same as sample IO, suggested to use the first test case to check whether your output format is valid.

  2. For the test cases from the second to the fifth, you can get an AC by purely by implementing this problem. No additional optimization is required.

  3. For the test cases from the sixth to the eighth , some optimization back in 12022 - prefix sum is required. Recall that :

How to estimate the running time of your code?

A usual computer can run 10^9 basic operations (such as +, -, &, |) in 1 second. Although this depends on the judging server, this number serves as a good estimation for the running time of your code. Try to figure out how much operations your code needs to execute to finish all the computations (since not all operations in your code are basic operations, another estimate criterion is 10^8 operations (+, -, *, /, =, ...) in 1 second)!

Output

For each query, please output how many species of bacteria there are in the given range.  Remember to add a new line character after every output.

Explanation of sample IO

For the first query (see orange range), in range [5, 6] there is one bacteria of species 1 and one bacteria of species 0. Since there are two kind of species, output 2. For the second query (see purple range), in range [3, 5] there are two bacteria of species 3 and one bacteria of species 1. Since there are two kind of species, output 2.

Sample Input  Download

Sample Output  Download

Tags




Discuss