# | Problem | Pass Rate (passed user / total user) |
---|---|---|
13390 | Domo the Builder |
|
13391 | Domo the Train Conductor |
|
13393 | Domo the Engineer |
|
Description
Domo is a builder, he wants to build some one-way bridges to travel around islands.
Given a series of one-way bridges and the island where Domo is in the beginning, please find which island(s) Domo can reach.
For example, the sample gives 5 islands and 5 one-way bridges shown as below:
It's easy to find that we can reach islands with indices 1, 2, and 3.
Input
The first line consists of three integers N, K, and S (1 ≤ N ≤ 1000, 1 ≤ K ≤ N⋅(N-1), 1 ≤ S ≤ N) denoting that the number of islands, the number of one-way bridges, and the island where Domo is in the beginning.
In the following K lines, each line consists of two integers A, B (1 ≤ A, B ≤ N) denoting that there's a one-way bridge from A to B.
Output
The output only consists of one line, indicating the islands that Domo can reach.
Notice that if there are multiple islands that Domo can reach, print them in increasing order and separate them by whitespace.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Domo is a train conductor, he wants to adjust the train he's driving.
There are five instructions below with the description:
1. AddFront num
Add a train carriage with the index num in front of the train.
2. AddBack num
Add a train carriage with the index num in back of the train.
3. Delete num
Delete all the train carriages with the index num from the train. (If the train has no any carriage with the index num, do nothing)
4. DeleteFront
Delete the first element of the train. (If the train is empty, do nothing)
5. Swap
Reverse all train carriages. (If the train is empty, do nothing)
For example:
AddFront 5 makes the train [4, 1] become [5, 4, 1].
AddBack 5 makes the train [4, 1] become [4, 1, 5].
Delete 5 makes the train [5, 4, 1, 5, 3] become [4, 1, 3].
DeleteFront make the train [1, 2, 3, 4] become [2, 3, 4].
Swap makes the train [2, 6, 3] become [3, 6, 2].
The train is empty in the beginning. Given a series of instructions, please print the index of train carriages after all instructions are executed.
This is a partial judge problem, you're asked to implement these 5 functions.
If you get a TLE:
Try to use the pointer head and back wisely, which can make the AddFront and AddBack instructions faster!
If you get an MLE:
Remember to free the nodes you've deleted!
Input
The input consists of multiple instructions (1 ≤ number of instructions ≤ 105)
the index of each instruction is a positive integer and not greater than 102.
Output
The output only consists of a line denoting the train carriage indices after all the instructions.
It's guaranteed that the output consists of at least one carriage.
Sample Input Download
Sample Output Download
Partial Judge Code
13391.cPartial Judge Header
13391.hTags
Discuss
Description
Domo is an engineer, he wants to zip the string and send it to his friends.
Given the sequence contain only English letter or digit, the runs of data(sequences in which the same data value occurs in many consecutive data elements) will be stored as a single data value and count, rather than as the original run.
Take sequence aaabbb444 for example, aaabbb444 can be encoded to 3a3b3'4'
Since there are 3 consecutive a, 3 consecutive b, and 3 consecutive '4' (separate the digit data and the digit count via the apostrophe).
When there are less than three consecutive "letters", do not compress it.
For example, aabbbdcccc should be encoded to aa3bd4c.
When there are non-consecutive "digits", simply store the digit, do not store the count.
For example, aabbb1ccc2dd33dd should be encoded to aa3b'1'3c'2'dd2'3'dd
Besides encoding, your friend is also interested in the compressing rate of the result, which is defined by
Compress Rate = (length of the encoded string) / (length of the original string).
Input
Given a sequence containing only English letters or digits.
(2 ≤ the length of the sequence ≤ 1000)
Output
Print out the zip string and the compression rate, both followed by a newline character.
If the compression rate is less than 1.0 then print out "Compress rate: X.XXX" with the result (round to the third digit after the decimal point), otherwise print out "The string can't zip".
You can use printf("Compress rate: %.3f\n", rate) for printing the result.