zoukankan      html  css  js  c++  java
  • HD1085 Holding Bin-Laden Captive!

    Problem Description

    We all know that Bin-Laden is a notorious terrorist, and he has disappeared for a long time. But recently, it is reported that he hides in Hang Zhou of China!
    “Oh, God! How terrible! ”

    Don’t be so afraid, guys. Although he hides in a cave of Hang Zhou, he dares not to go out. Laden is so bored recent years that he fling himself into some math problems, and he said that if anyone can solve his problem, he will give himself up!
    Ha-ha! Obviously, Laden is too proud of his intelligence! But, what is his problem?
    “Given some Chinese Coins (硬币) (three kinds-- 1, 2, 5), and their number is num_1, num_2 and num_5 respectively, please output the minimum value that you cannot pay with given coins.”
    You, super ACMer, should solve the problem easily, and don’t forget to take $25000000 from Bush!

    Input

    Input contains multiple test cases. Each test case contains 3 positive integers num_1, num_2 and num_5 (0<=num_i<=1000). A test case containing 0 0 0 terminates the input and this test case is not to be processed.

    Output

    Output the minimum positive value that one cannot pay with given coins, one line for one case.

    Sample Input

    1 1 3 0 0 0

    Sample Output

    4

    大神说,这道题用母函数,但惭愧的说,自己还不了解母函数这东东,只能用数学的知识去做。这道题也告诉我们用1 ,2,5制作硬币,能够用尽可能少的硬币种数去表示其它的数

    #include<iostream>
    using namespace std;
    int main(){
        int a,b,c;
        while(cin>>a>>b>>c)
        {
            if(a==0 && b==0 && c==0)
                break;
            else{
                if(a==0)
                    cout<<1<<endl;
                else{
                    if(a+2*b<4)
                        cout<<a+2*b+1<<endl;
                    else
                        cout<<a+2*b+1+5*c<<endl;
                    }
                }
        }
        return 0;
    }
    //一定要注意{},不要偷懒
  • 相关阅读:
    在vi或者vim中显示行号
    Ubuntu 14.10 下进程实时IO监控iotop命令详解
    Ubuntu 14.10 下网络流量实时监控ifstat iftop命令详解
    Ubuntu 14.10 下运行进程实时监控pidstat命令详解
    Ubuntu 14.10 下CPU实时监控mpstat命令详解
    Ubuntu 14.10 下awk命令详解
    Ubuntu 14.10 下sort,uniq,cut,wc命令详解
    Ubuntu 14.10 下sed命令详解
    Ubuntu 14.10 下grep命令详解
    Ubuntu 14.10 下Ganglia监控Spark集群
  • 原文地址:https://www.cnblogs.com/LZYY/p/3291769.html
Copyright © 2011-2022 走看看