zoukankan      html  css  js  c++  java
  • HDU 1085 Holding Bin-Laden Captive!(母函数,或者找规律)

    Holding Bin-Laden Captive!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 17653    Accepted Submission(s): 7902


    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
     
    Author
    lcy
     
    Recommend
    We have carefully selected several similar problems for you:  1398 2152 2082 1709 2079 
     
    一开始想用dp,但是dp[1000][1000][1000]开不了那么大(三维数组最大是[790][790][790]codeblocks亲测),所以直接找规律。要细心,wa了两次,第一次是少了3,0,1这种情况,我的答案是9,正确答案是4。第二次是因为没有写&&n1+n2+n5>0 (orz...)
     
    #include<queue>
    #include<math.h>
    #include<stdio.h>
    #include<string.h>
    #include<string>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define N 1002
    int n1,n2,n5;
    
    int ziji(int n1,int n2,int n5)
    {
        int ans;
        if(n1==0)ans=1;
        else if(n2==0&&n1<2)ans=2;
        else if(n1==1&&n2==1)ans=4;
        else if(n1==2&&n2==0&&n5>0)ans=3;
        else if(n1==3&&n2==0&&n5>0)ans=4;//第一次少了这种情况
        else
        {
            ans=n1+n2*2+n5*5+1;
        }
        return ans;
    }
    
    int main()
    {
        while(~scanf("%d%d%d",&n1,&n2,&n5)&&n1+n2+n5>0)
        {
            cout<<ziji(n1,n2,n5)<<endl;
        }
        return 0;
    }

    母函数方法:

     
  • 相关阅读:
    5分钟轻松应对 MySQL DBA 面试
    数据库优化总结
    13-Python与设计模式--责任链模式
    22-Python与设计模式--状态模式
    23-Python与设计模式--设计原则
    21-Python与设计模式--备忘录模式
    20-Python与设计模式--解释器模式
    19-Python与设计模式--观察者模式
    17-Python与设计模式--迭代器模式
    18-Python与设计模式--访问者模式
  • 原文地址:https://www.cnblogs.com/wmxl/p/4781979.html
Copyright © 2011-2022 走看看