輸入糖果和獨角獸

 

若存在大量糖果可使獨角獸全部升級

則輸出獨角獸

 

若糖果+獨角獸小於等於12

則無法升級,輸出0

 

先將所有糖果用完

每升級一隻銷耗10顆糖果,因為升級送一顆,轉送鐵殼蛹再送一顆

 

考慮將獨角獸轉換換取糖果

先將剩餘糖果用完,故轉讓12-candy隻獨角獸,再升級一隻

 

 

 

接著每升級1次,消耗11隻獨角獸

因為,前次留有2顆糖果 (升級+轉送),故再轉送9隻,外加升級消耗1隻

 

輸出答案

 

#include<iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int candy, bee;
    int total;
    while(cin >> candy >> bee)
    {
        if(candy/12 >= bee)
        {
            cout << bee << endl;
            continue;
        }
        else if(candy + bee <= 12)
        {
            cout << "0" << endl;
            continue;
        }

        total = 0;
        while(candy >= 12)
        {
            total += candy/12;
            bee -= candy/12;
            candy -= (candy/12)*10;
        }
        
        if(bee > 12 - candy)
        {
            bee -= 12 - candy + 1;
            total += 1 + bee/11;
        }
        
        cout << total << endl;
    }
    
    return 0;
}

arrow
arrow
    全站熱搜

    大神(偽) 發表在 痞客邦 留言(0) 人氣()