| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10673 | Queueing |
|
| 10861 | Parentheses Matching |
|
| 11495 | Missionaries and Cannibals - 6 points |
|
Description
You need to write a program to simulate a queue of names. Each name is a string consisting of English letters only. There are three operations:
1. “Push [name]”, which means to enque name in the queue.
2. “Pop”, which means to deque. If the queue is empty, this operation takes no effect.
3. “Front”, which means to print out the name in the front of queue. If the queue is empty, print "empty" (without quotes).
Case1 : #operation <= 10^2, There will be no "Pop" and "Front" command when queue is empty.
Case2 : #operation <= 10^3. There will be no "Pop" and "Front" command when queue is empty.
Case3 : #operation <= 10^4.
Case4 : #operation <= 10^6.
Input
Each line contains one of the following operations. “Push [name]” (without quotes), “Pop” (without quotes), “Front”(without quotes). The length of each name is at most 10.
Output
For each “Front” operation, print out the name in the front of the queue.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
A string is said to be valid if it matches one of the following rules:
(1) The string is an empty string.
(2) If a string S is valid, then {S}, [S], (S) and <S> are valid.
(3) If strings S1 and S2 are both valid, then S1S2 is valid.
Given a string consisting of parentheses, determine if it is a valid string.
Input
The first line of the input contains an integer N (N ≤ 1000) denoting the number of test cases followed by. Each of the next N lines corresponds to a test case, which contains a string consisting of parentheses, and the maximum string length will be no more than 1000. Note that an empty string (a line which contains the newline character only) may be contained in the input and it should be considered as a valid string according to rule (1).
For case 1,2 : 1<N<100. 0<=length<100
For case 3,4 : 1<N<1000. 0<=length<1000
Output
For each test case, print “Case i:” and then “Yes” or “No” to indicate that the string is valid or not, separated by a space character. i is the test case number starting from 1.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Notice! You need to enable the flag -std=c++11 to compile the code!
- In codeblocks, go to Settings->Compiler->check the option "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]"->OK
- In dev-c++, go to Tools->Compiler options->check "Add the following commands ..."->type in "-std=c++11"(without qoute) ->OK
X missionaries (傳教士) and Y cannibals (食人族) must cross a river using a boat which can carry at most two people, under the constraint that, for both banks, if there are missionaries present on the bank, they cannot be outnumbered by cannibals. If they were, the cannibals would eat the missionaries. The boat cannot cross the river by itself with no people on board. Initially, they are all on the left bank.
List all possible solutions to the given X and Y.
This is a Partial Judge problem.
We define a "State" as follows:
// A state contains five components: // The first two components denote the current numbers of // missionaries and cannibals at the left bank of the river. // The third and fourth components denote the current numbers // of missionaries and cannibals at the right bank. // The fifth component denotes the location of the boat: // 1 means "left bank" and -1 means "right bank". using State = vector<int>;
Basically, you need to implement five functions:
// the starting porint of your implementation void solve(); // extend to other possible states from a certain state set<State> extend(State s); // may use s[4] to indicate the direction of move State Go(State s, int missionary, int cannibal); // check the validity of a state bool valid(State s); // check if all people are at the right bank bool found(State s);
Notice that, if you don't want to follow the scheme we provide, you can just implement the sovle() function and make the others blank, e.g. bool found(State s) { }.
Input
A single line containing two integers seperated by a space.
The first number is X denoting the number of missionaries. The second number is Y denoting the number of cannibals.
Actually, you don't need to worried about the input, we handle it for you.
Output
List all possible solutions one by one. "done" denotes the end of a solution.
A solution contains several moves. A move is represented by a line with the format of:
(#M on the left bank, #C on the left bank)(#M on the right bank, #C on the right bank) [left/right]
M: missionary, C: cannibal, left/right: of the boat.
There is
Just like below,
(1, 1)(1, 1) right
(2, 1)(0, 1) left
(0, 1)(2, 1) right
(0, 2)(2, 0) left
(0, 0)(2, 2) right
done
Also, we've already handled the output functionality for you, so you don't have to worried about this, either.
You just need to add your solutions to the variable set<list<State>> _solutions and the order of addition doesn't matter.