Добро пожаловать на 2016-2017 CT S03E06: Codeforces Trainings Season 3 Episode 6. Продолжительность тренировки — 5 часов. Тренировка открыта как для команд, так и для индивидуальных участников. После ее окончания вы можете дорешивать задачи тренировки или поучаствовать в ней виртуально, если не смогли принять участие одновременно со всеми. Пожалуйста, участвуйте в тренировке честно.
Перейдите в раздел Тренировки для регистрации и участия.
Ориентировочный старт: 12 октября 2016 г., 16:10 (Московское время).
Так как это тренировка, то возможно набор задач будет расширен, если для значительного количества участников он окажется простым.
Условия задач будут на английском языке, ведь мы же готовимся к ACM-ICPC!
Удачи!
How to solve problem I?
We can solve the problem for each connected component independently.
If there is an odd number of vertices in a connected component, there is no answer (otherwise the sum of all degrees in the resulting graph is odd for this component, which is impossible).
Let's find an arbitrary (rooted) spanning tree. Now we can build the answer starting from leaves. For each node, we will do the following: if the number of edges from kids to it is even, we add an edge from this vertex to its parent. Otherwise, we don't do anything. Why does it work? For all vertices, except, possibly, for the root, the answer is correct by design. The sum of all degrees must be even. The sum of all degrees of all vertices except for the root is odd (as the number of such vertices is odd and their degrees are odd). Thus, the degree of the root is also odd.
How can I solve problem M ? May be the easiest problem. But I can't it figure out.
Problem M: Idea: Count of reachable numbers less than 10 ^ 9 is small, around 100,000.
So you can either do a dynamic programming using map<int,bool> dp where dp[i] denotes whether it is a losing state or winning state. A state is winning iff you can reach some losing state.
DP Using Map
DP Using Array — since 2, 3, 5, 7 are the possible prime factors of reachable numbers.
I think I have a better solution. Consider the smallest numbers of the form (9^i * 2^i) and (9^j*2^(j-1) which are >= given number n. Take their min and if (9^i * 2^i) is lesser Ollie wins, else Stan wins.
This works since whenever Ollie wins, steps will be 2*9*2*9*...*2*9 and when Stan wins, steps will be 9*2*9*2*...*2*9.
So, you can go from right to left in the sequence i.e. start from num=1. Do num*9 and num*2 alternatively till (num < n). If the last step was num*2, Ollie wins, else Stan wins.
How to solve E?
You can find the probability "No 2 man chose the same color" that probability equals to product of (2 * C — 2 * i) / (2 * C — i) with 1 <= i < M
Test data for J is weak. This test: 10 100 9999999...999 (5000 numbers of 9) makes submission from HAT and SkyTeam TLE
How to pass test 3 of problem D ?
What's the problem with this solution for problem H? It gives me WA on test 4.
How to solve B?
how to solve E ??
Answer doesn't depend on count of ladies.
Imagine that gentelmens choose colors. Calculate dpi — probability of first i gentelmens to have different colors. Suppose that gentelmens choose from two variants of each color.
dpi = dpi - 1·pi
where pi is probability i-th gentelmen to choose new color
pi = (2·с - 2·(i - 1)) / (2·c - (i - 1))
Answer is 1 - dpm. We don't need multiply all pi by large m because answer is very small. In my code I calculated i from m - 300000 to m.
Problem E was hard to understand for me :(
How to solve problem A?