This is the problem of cses coin piles I have only one doubt why we have to check for this condition min(a, b) * 2 >= max(a, b)? and other approaches and hints will be highly appreciated.
# | User | Rating |
---|---|---|
1 | tourist | 3805 |
2 | maroonrk | 3637 |
3 | Benq | 3513 |
4 | ecnerwala | 3506 |
5 | MiracleFaFa | 3466 |
6 | slime | 3428 |
7 | jiangly | 3415 |
8 | Radewoosh | 3399 |
9 | greenheadstrange | 3393 |
10 | djq_cpp | 3391 |
# | User | Contrib. |
---|---|---|
1 | awoo | 192 |
2 | -is-this-fft- | 191 |
3 | Monogon | 185 |
4 | Um_nik | 182 |
4 | YouKn0wWho | 182 |
6 | maroonrk | 170 |
7 | antontrygubO_o | 168 |
8 | errorgorn | 166 |
8 | kostka | 166 |
8 | SecondThread | 166 |
This is the problem of cses coin piles I have only one doubt why we have to check for this condition min(a, b) * 2 >= max(a, b)? and other approaches and hints will be highly appreciated.
Name |
---|
No we dont need that condition
thank you but i am not able to understand your code
At which part ? :(
You can construct the equation system and find out. The solution must be nonnegative integers.
Let x be the number of moves that remove one coin from the left pile and two coins from the right pile. Let y be the number of moves that remove two coins from the left pile and one coin from the right pile. This yields a system of equations that you can solve: a = x + 2y, b = 2x + y. Through solving the system, you can rederive the condition you mentioned.
thank you for the reply i understand your concept up to some extent om solving the eqns i am getting two condition
2*a>=b
2*b>=a
but from where max and min is coming into picture?
take both piles mod 3 then hardcode in 2-1 2-0 etc
thank you for the reply but i couldnt understnd the line ** hardcode in 2-1 2-0 etc**?
What if the testcase is
100 2
? As you are saying,100 % 3 == 1
and2 % 3 == 2
. And thus, you get an wrong answer.I found an answer from codechef helpful.