Блог пользователя arpitP

Автор arpitP, история, 3 года назад, По-английски

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.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
3 года назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

No we dont need that condition

My way
»
3 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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.

  • »
    »
    12 месяцев назад, # ^ |
    Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится
    bool calc(ll a,ll b){
        if(a==0 && b==0) return true;
        if(2*a==b || 2*b==a) return true;
        ll intres = (2*a) — b;
        ll y=0;
        if(intres>0 && intres%3==0) y=(intres/3);
        else return false;
        intres = (b-y);
        if(intres>0 && intres%2==0) return true;
        return false; 
    }
    

    I think this would be more simple to understand