Hi guys ! Please provide editorial for this problem : Interactive Bulls and Cows (Hard)
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Hi guys ! Please provide editorial for this problem : Interactive Bulls and Cows (Hard)
Name |
---|
u can just google it u know..
In total there are 5040 (=10*9*8*7) different possible solutions. You can put them all into a list. We have too make sure, that each solution can be guessed in a total of maximal 7 moves.
The choice of the guesses matter a lot. A bad guess would be
0000
. Because if the response is0 0
, than you still have 3024 possible solutions in your list, which is way too many. In the worst case (if the solution doesn't contain a zero) we will probably not be able to determine the solution with the remaining six guesses.A much better first guess would be
0011
. If the response is0 0
, only 1680 possibilities remain in your list. If the response is0 1
only 1344, and with the responses0 2
,1 1
or2 0
only 224 remain. Therefore in the worst case we can still eliminate 66.6% of all the entries in our list.With each guess we want to eliminate as many possible solutions of our list as possible. But since the approach should always work, we have to make sure that we eliminate as much as possible if we receive the worst bulls/cows response.
So how do we compute a good guess? Simply by simulating. For each possible guess, compute how many in the list survive for each possible response. Choose the guess, where the maximal list size under all responses is minimal.
Here is my solution: 23398322. The code is not beautiful at all. In the vector
left
I keep all answers, that are still possible. The functionchoose_best
does the simulation and functionguess
prints a guess, reads the bulls/cows response and updatesleft
.Such an approach is also known as MinMax-Algorithm. However MinMax often simulates the complete game (What is the best move, so that with the opponents best move and my best response after it and his best response, ... lets me win.) But this is not necessary here. Only simulating the first move and all possible bulls/cows responses is enough to always find the answer in 7 guesses.
Can you please explain why is it necessary to include the this condition while rejecting ? That is why should we include num when it produces same left vector size and is present in the left also.
Condition-> "else if (worst == worst_result && count(left.begin(), left.end(), num)) { best = num; }".
I really like your solution so simple to understand and with such a clean implementation.This is the only solution i found which does not use randomization and is deterministic.
I don't think that it is really necessary. It probably also works without it.
I guess the intuition for it is, that if the guess is one of the remaining possible solutions, then there is a small chance that we actually guess correctly and finish early. If the guess is no longer possible, then there is zero chance of finishing early.