| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11490 | The Cat Society |
|
| 11773 | Integer pointer array |
|
| 12078 | Hurry! |
|
| 12094 | Coding in terminal |
|
| 12099 | String sorting |
|
| 12568 | Reverse Linked List ver 2 |
|
| 12574 | New Year |
|
| 12584 | The Beauty of Distributing |
|
Description
Wild cats take care of each other in the wild. However, when winter comes, the preys are not enough to feed all the cats. Therefore, the cats dine according to the order of their occupations. The order is as follows:
1. elder
2. nursy
3. kitty
4. warrior
5. apprentice
6. medicent
7. deputy
8. leader
In the tradition of the cat society, three different cats serve as the medicent, the deputy, and the leader respectively.
As for the other cats, except that the apprentices have the dining priority of the young over the old, for the other occupations, the old have higher priority. If the occupations and the ages of two or more cats are the same, they will dine in lexicographic order according to their names.
Input
There are multiple test cases.
The first line of each test case contains two integers N and M, indicating the number of cats and the portions of food respectively, where 0<N,M<=10000.
The next N lines are the information of each cat, including name, occupation, and age.
The length of the names will not exceed 30 letters and will contain no spaces.
Output
Please output the cats that could eat the food in order, each name a line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given an integer pointer array **ptr with size N, and an integer array *array with size (N+1)*N/2. Please use malloc function to allocate memory to **ptr and *array. The *array is an ascending sequence of numbers. Each pointer in array **ptr shall point to one element of *array. And the elements pointed by the **ptr are also ascending.
For example, when n = 5, the size of **ptr will be 5, and the size of *array will be 15. The first pointer of **ptr is *ptr[0] which points to array[0], and the second pointer of **ptr is *ptr[1] which points to array[1], and the third pointer of **ptr is *ptr[2] which points to array[3], and the fourth pointer of **ptr is *ptr[3] which points to array[6].
Input
The first line is size of **ptr
The second line is offset
offset < size <10000
Output
Print each pointer of **ptr + offset
Note that you need to print a newline character ‘\n’ after each number, that is, just one number will be shown in each line of the output.
Sample Input Download
Sample Output Download
Partial Judge Code
11773.cPartial Judge Header
11773.hTags
Discuss
Description
Ben is hurrying for the restroom!
As you might know, men have a habit when choosing which urinal (小便斗) to use: choose the one from other people as far as possible.
Let's define this habit more formally.
- Considering the i-th urinal (index increases from left to right), define Li and Ri as
- Li: the number of urinals between the rightmost people in the left of the i-th urinal and the i-th urinal;
- Ri: the number of urinals between the leftmost people in the right of the i-th urinal and the i-th urinal.

- By the way, there are always 2 security guards in the leftmost and rightmost of the restroom (not occupying any urinal) for some unknown security reason. They will also be treated as people mentioned in the above definition when determining distances.

- When Ben arrives at the restroom, he will pick the i-th urinal such that min(Li, Ri) is the maximum among all available urinals. If there exist multiple available choices, then he will pick the one with the smallest i (the leftmost one).
Let's give an example to demonstrate how everything's going:
-1234567- (index of urinal)
| i | Li | Ri |
| 1 | 0 | 2 |
| 2 | 1 | 1 |
| 3 | 2 | 0 |
| 4 | - | - |
| 5 | 0 | 2 |
| 6 | 1 | 1 |
| 7 | 2 | 0 |
So for the man who just arrives at the restroom, he will choose the 2nd urinal, making the status become
G0101000G
And now the question is:
If Ben is the k-th man arriving at the restroom and suppose no one ever leaves his urinal, which urinal will Ben choose?
Input
Input consists of multiple testcases. There is an integer T in the first line, indicating there are T testcases.
Each testcase consists of 1 line, containing 2 integers N and K, where N is the total number of urinals, and K means Ben is the K-th man arriving at the restroom.
It is guaranteed that
- T <= 10
- K <= N <= 3000
Hint
1. No recursion. Loop is enough!
2. Testcase
- Testcase1: T = 1, K = 1
- Testcase2: T <= 10, K = 1
Output
For each testcase, print out the index of the urinal that Ben will choose.
(Index starts from 1, and increases from left to right.)
Sample Input Download
Sample Output Download
Tags
Discuss
Description
[Update] There's new-line characters ('\n') in the input test cases, you should ignore it.
[Update] You do not need to add an extra '\n' at the end of output!
[Notice] Input contains space character (' ')!
Some people prefer to use vim to code.
Vim is a powerful text editor. Using vim, you can code in a terminal. Usually we code with vim on a remote server, since there is no GUI applications (like CodeBlocks or Visual Studio Code) available.
Besides the basic functionality, you can install a variety of plugins to make vim looks fancy and convenient.
This is how it looks like to coding with vim

Now, we ask you to simulate the most basic functionality of a text editor: typing.
Given a operation sequence, please show us the final look on the terminal. (Suppose we started in "Insert" state in vim, that is, what we type will be treated as text and directly shows on the screen. For those who don't know the "Insert" state, try google for it or just ignore it and keeps reading the problem description~)
Input
Input consists of a single line, representing the operation sequence.
Below we explain the meaning of each character in the operation sequence:
- Normal latin characters (uppercase/lowercase English characters) are treated as character input. Whatever the character is, show it on the screen.
- The special operations starts with a "\" (without quotes), follow by some operation indication characters. Below we list out all possible special operations:
- "\n", user types Enter. Print a '\n' (new line character).
- "\b", user types a backspace. Remove the character right before the cursor(游標) (if there is any).
- "\l", move cursor left. If the cursor is at the beginning of current line, then go to the end of previous line (if exists).
- "\r", move cursor right. If the cursor is at the end of current line, then go to the beginning of the next line (if exists).
- "\s [x y]", change the terminal size. x and y are positive integers. There is only one space character ' ' between s and [, x and y.
Suppose the initial terminal size is 80*24. (x=80, y=24). x is the width of the terminal, means there can be at most x characters (including ' ') in a single row on the screen.
The final output is guaranteed to not exceed the size of the terminal. (Total rows on screen will be less than or equal to y)
The length of operation sequence won't exceed 105.
Output
Show the final look on the terminal.
Notice the width of the screen. If a line contains too many characters to fit into the width x, then you should print the remaining characters of this line on the following rows on screen.
For example :
t\b\bThis is the sample input\l\l\l\l\bI\r\r\r\r\n\s [10 20]
The first line will be “This is the sample Input\n”(without quotes).
But since the the terminal size is 10*20, the output should be as following(without quotes):
“This is th
e sample I
nput
“
For more information, please refer to Sample Input and Sample Output.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given several strings, please output them in alphabetical order.
Input
Input consists of several lines, each of them is a string.
It is guaranteed that
- # of strings won't exceed 200000
- Length of each string won't exceed 100
Output
Print out strings in alphabetical order, one string per line.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Given several operations, push x, pop, print, reverse, create a linked list dynamicly.
- push x: Add one Node (with data = x) at the front of linked list.
- pop: Delete the Node at the front of linked list.
- reverse: reverse the current linked list
- print: output the linked list in given format.
You have to implement 3 functions:
1. void Push(Node** ptr_head,int x)
2. void Pop(Node** ptr_head)
3. void Reverse_List(Node** ptr_head)
Note: Modify the Node* head by Node** ptr_head


Input
There’re operations on several lines.
All operations are one of push x, pop, print, reverse.
It’s guaranteed that:
- Number of operations is less than 5,000,000
- Integer x is in [−1000,1000]
- The maximum length of linked list is less than 10,000.
Output
Output the linked list for every print.
Sample Input Download
Sample Output Download
Partial Judge Code
12568.cPartial Judge Header
12568.hTags
Discuss
Description
Bob is a young kid. He thinks New Year is a tradition that involves many troublesome events such as family reunion, etc. Luckily, there is always one event that can cheer him up - receiving red envelopes.
His family tree looks like this :

However, only his parents, uncles (disregard uncle-in-law), aunts (disregard aunt-in-law), grandparents, grand-grandparents, grand-...-grandparents will give him one red envelope in New Year's Eve (circled in the family tree), so the family tree he cares looks like the following graph. Bob calls this version of family tree "New Year Family Tree". (Relatives in blue nodes are those who will give Bob red envelopes)

Since Bob has a large family, he can receive many red envelopes in New Year's Eve. Given Bob's "New Year Family Tree", please tell Bob how many envelopes he can get.
Input
The input is in the following format :
N P1 P2 P3 ... PN
-
N is an integer which means there are N people in the "New Year Family Tree" (including Bob). People are numbered from 1 to N. Bob is numbered with N.
-
There are N integers in the second line. Pi (the i-th number counted from the left) is the parent of person i. If Pi = -1, it means that person i 's parent is too old and has passed away.
Technical Restrictions
-
1 <= N <= 10^5
-
1 <= Pi <= N or Pi = -1
-
Only the oldest grand-...-grandparents has passed away in the "New Year Family Tree"
Output
Output how many red envelopes Bob will get. Remember to add a newline character in the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Little brick is once playing a RPG game.
In this game, there are some magical reels(魔法卷軸) that can increase your skill level.
As a serious OCD patient (強迫症患者),
he can only accept that every skill he has is at the same level.
At the beginning, every skill is at level 0,
and he has N magical reels,
the ith reel can increase one of his skill by Xi levels.
LittleBrick wants to have as many skills as possible,
and he also want to use all N reels.
Tell LittleBrick what is the maximum number of skills he may have.
ouo.
For Example 1:
6
1 1 2 2 3 3
The answer is 4, since you can make 4 skills to reach the same level 3,
by distributing the reels like (1, 2), (3), (1, 2), (3)
For Example 2:
5
1 1 2 5 3
The answer is 2, since you can make 2 skills to reach the same level 6,
by distributing the reels like (1, 5), (1, 2, 3)
For Example 3:
3
1 2 4
The answer is 1, since you can make only 1 skill to reach the same level 7,
by distributing the reels like (1, 2, 4)
Input
The first line contains an integer T, represent the number of test cases.
For each test case, the first line is an integer N,
which represents the number of reels LittleBrick has.
The next lines contain N number Xi separated by spaces,
which represents the number of levels the ith reels can increase to a single skill.
It is guarantee that:
1 <= T <= 10,
1 <= N <= 10,
1 <= Xi <= 100
Output
For each test case,
output the maximum number of skills LittleBrick can learn,
and a newline character after the answer.