arpitP's blog

By arpitP, history, 4 years ago, In English

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.

  • Vote: I like it
  • +4
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

No we dont need that condition

My way
  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thank you but i am not able to understand your code

    • »
      »
      »
      4 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      At which part ? :(

      • »
        »
        »
        »
        3 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        why have you done b-1 and taking min at each step, i understand the equation method but not this

»
4 years ago, # |
  Vote: I like it +3 Vote: I do not like it

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.