# | Problem | Pass Rate (passed user / total user) |
---|---|---|
11495 | Missionaries and Cannibals - 6 points |
|
13927 | Play the Game |
|
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.
Sample Input Download
Sample Output Download
Partial Judge Code
11495.cppPartial Judge Header
11495.hTags
Discuss
Description
Driving me insane
Come play the game, play the game, play the game
Play the game"
Notwithstanding, today you're playing the game not of love but of cards. There is a deck with \(n\) cards each of which has a non-negative integer written on in front of you. From the top of the deck, you could perform the following actions sequentially:
- If the integer is positive, then you could either put the card on the top of your own pile, or discard it.
- Otherwise the integer is zero, you could remove the card from the top of your own pile and obtain the score of amount the integer written on, if your pile is not empty.
Initially, your pile is empty. As Freddie sang, "It’s so easy when you know the rules / It’s so easy, all you have to do / ...", you know all the integers written on every card beforehand. Therefore, you're crurious about what the maximum score that you could obtain is.
Input
The first the would be an integer \(n\).
And then, there would be \(n\) integers \(s_i\) in the following line, representing the integers written on the cards from top to bottom.
For 50% of the testcases, \(n\leq5000\). As for the rest of the testcases, \(n\leq10^5\). It's guranteed that all integers written on the cards are non-negative and less than \(2^{31}\);
Output
Please print out a single integer that is the maximum score you could obtain. Beware of possible overflow!