# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11490 | The Cat Society |
|
12568 | Reverse Linked List ver 2 |
|
13086 | Golden Ratio Overheat |
|
13402 | Flip Game |
|
14166 | Doraemon's dorayaki |
|
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 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
Last Pokemon Contest (神奇寶貝華麗大賽) between Satoshi (小智) and Haruka (小遙) ! After Satoshi won the victory in Battle Pyramid, Satoshi and Haruka signed up for an unofficial Pokemon Contest in Terracotta Town.
Pokemon Contest is a contest in which trainers and Pokemons coordinate strength and beauty. It is divided into two stages. In the first stage, the Performance Stage, trainers and their Pokemons will perform moves to showcase their styles and skills. In the second stage, the Battle Stage, trainers battles against each other as well as demonstrating charm of their Pokemons.
Satoshi and Haruka met in the Battle stage, where Satoshi's Sceptile (蜥蜴王) fought against Haruka's Blaziken (火焰雞). In the final ten seconds of the battle, Haruka's Blaziken activates Blaze (猛火) and fires Overheat (過熱). To battle in a dazzling style, the pattern of Overheat is cleverly designed with golden ratio:
The pattern of Overheat can be expressed with a string. First, Haruka and Blaziken design two short patterns F0 and F1. Then they generate longer patterns using the following recurrence formula: Fn-2 + Fn-1 = Fn (+ means string concatenation). Finally, Haruka tells Blaziken a number n, and Blaziken fires the Overheat with pattern Fn.
Given F0, F1, n, and k, please find out the k-th character in Fn.
For full episode, please google "AG191 Satoshi vs. Haruka! Last Battle!!" or refer to this page.
Explanation on Sample IO
All test data provide same F0 = "abc", F1 = "def". We can generate the following patterns:
-
F2 = "abcdef"
-
F3 = "defabcdef"
-
F4 = "abcdefdefabcdef"
The first test data asks 0-th character of F0, therefore output 'a'. Similarly, the outputs for the second to fifth test data are 'd', 'f', 'f', 'e', respectively.
Input
The input contains multiple test data. The first line of input contains an integer T, being number of test data. After that are T test data.
The first line of test data contains two non-empty strings F0 and F1.
The second line of test data contains two integers n and k.
-
1 <= T <= 100
-
F0 and F1 contain only lower case alphabets (
a-z
) and have length no greater than 2000. -
0 <= n < 60 and 0 <= k < |Fn|, where |Fn| is length of Fn
Output
For each test data, output the answer in a single line. Remember to add new line in the end.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Flip game is played on a rectangular N x M field with two-sided pieces placed on each of its N x M squares. One side of each piece is white and the other one is black and each piece is lying either it's black or white side up. Each round you flip some pieces, thus changing the colors of their upper sides from black to white and vice versa. The pieces to be flipped on the N x M field are chosen every round according to the following rules:
- Choose any one of the N x M pieces.
- Flip the chosen piece and also all adjacent pieces to the left, to the right, to the top, and to the bottom of the chosen piece (if there are any). That is, depending on the position of the chosen piece, there can be totally 3 to 5 pieces flipped.
Consider the following position as an example:
bwbw
wwww
bbwb
bwwb
Here "b" denotes pieces lying their black side up and "w" denotes pieces lying their white side up. If we choose to flip the 1st piece from the 3rd row (this choice is shown at the picture), then the field will become:
bwbw
bwww
wwwb
wwwb
The goal of the game is to flip either all pieces white side up or all pieces black side up. You are to write a program that will search for the minimum number of rounds needed to achieve this goal.
If it's impossible, print "oops".
Input
The first line contains a single integer T (1 ≤ T ≤ 100). Then T test cases follow.
For each test case:
- The first line gives two integers N and M (1 ≤ N*M ≤ 16).
- Each of the next N lines consists of M ‘w’ or ‘b’ characters separated by spaces.
Limit:
Testcase 1: N = 1, M ≤ 4
Testcase 2: N = 1, M ≤ 16
Testcase 3: N ≤ 2, M ≤ 2
Testcase 4: N ≤ 4, M ≤ 4
Testcase 5: N ≤ 4, M ≤ 4
Output
For each test, output the minimum number of rounds to reach a winning configuration, in case such a configuration exists, or the word "oops".
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Doraemon aims to make a fortune from the significant daily price changes of dorayakis. He plans to buy a dorayaki on one day and sell it on another to profit from the price spread. To keep his plan secret, Doraemon will only hold one dorayaki at a time, meaning he must sell each one before buying another.
Given the dorayaki prices over a continuous span of N days, please calculate the maximum profit Doraemon can gain.
Example
N = 8 days, prices = [7, 2, 5, 6, 3, 8, 1, 9]
Buy on day 2 (-2) -> Sell on day 4 (+6) -> Buy on day 5 (-3) -> Sell on day 6 (+8) -> Buy on day 7 (-1) -> Sell on day 8 (+9)
Maximum profit = (-2) + 6 + (-3) + 8 + (-1) + 9 = 17
Input
- The first line contains an integer N (1 ≤ N ≤ 105), representing the number of days.
- The second line contains N integers: x1, x2, ..., xN (1 ≤ xi ≤ 109), where xi represents the price of dorayakis on the i-th day.
Output
Output a single line containing one integer — the maximum profit Doraemon can gain.
Constraints
- 60% - N ≤ 20. Use recursion to enumerate all kinds of ways to conduct transactions and return the maximum profit that can be gained.
- 40% - N ≤ 105. Try to think about what we can do with "unlimited transactions".