Hi guys ! Please provide editorial for this problem : Interactive Bulls and Cows (Hard)
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Hi guys ! Please provide editorial for this problem : Interactive Bulls and Cows (Hard)
Название |
---|
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.