zoukankan      html  css  js  c++  java
  • hdu1085

    继续母函数,趁热打铁,一次ac

    题意是1,2,5的硬币若干,打出最小的不能表示的钱数


    /*
     * =====================================================================================
     *
     *       Filename:  hdu1085.c
     *        Version:  1.0
     *        Created:  2013年11月20日 23时00分28秒
     *       Revision:  none
     *       Compiler:  gcc
     *         Author:  Wenxian Ni (Hello World~), niwenxianq@qq.com
     *   Organization:  AMS/ICT
     *    Description:  
     *
     * Holding Bin-Laden Captive!
    
    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 12830    Accepted Submission(s): 5741
    
    
    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
    典型的母函数问题,这样比较简单
    f(x) = (...)(...)...
     * =====================================================================================
     */
    #include<stdio.h>
    #include<string.h>
    
    int main()
    {
        int n1, n2, n5;
        int i, j, k, t;
        int a[8005], b[8005];
        while(~scanf("%d %d %d",&n1, &n2, &n5)&&n1!=0||n2!=0||n5!=0)
        {
           memset(b, 0, sizeof(b)); 
           memset(a, 0, sizeof(a)); 
           for(i=0;i<=n1;i++)
            a[i] = 1;
           for(i=0;i<=n2;i++)
            b[i] = 1;
    
            for(i=0; i<=n1; i++)
            {
                for(j=0; j<=n2; j++)
                {
                    a[i+2*j] += a[i]*b[j];
                }
            }
    
           for(i=0;i<=n5;i++)
            b[i] = 1;
    
            for(i=0; i<=n1+2*n2; i++)
            {
                for(j=0; j<=n5; j++)
                {
                    a[i+5*j] += a[i]*b[j];
                }
            }
    
            for(i=0;i<=8005;i++)
            {
                if(a[i]==0)
                {
                    printf("%d
    ",i);
                    break;
                }
            }
        }
        return 0;
    }
    


    每天早上叫醒你的不是闹钟,而是心中的梦~
  • 相关阅读:
    Arch Linux中安装Anaconda
    Windows下使用Diskpart格式化U盘
    Jupyter Notebook的安装
    Docker的脚本安装
    pip无法正常使用卸载并重新安装
    Arch更新时failed to prepare transaction
    Privoxy将Socks代理转化HTTP代理
    Arch Linux下Visual Stdio Code在格式化C代码时报错
    GNOME 3.28 启用桌面图标
    Appium入门(8)__控件定位
  • 原文地址:https://www.cnblogs.com/vintion/p/4117011.html
Copyright © 2011-2022 走看看