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;
    }
    


    每天早上叫醒你的不是闹钟,而是心中的梦~
  • 相关阅读:
    在 Android 4.1上,分析 input -- android framework 部分 2
    Linux内核spin_lock、spin_lock_irq 和 spin_lock_irqsave 分析
    module_init 和 late_initcall 区别
    在 Android 4.4.4 上,分析 input -- android framework 部分
    Android 输入系统 与 按键
    INIT_WORK和INIT_DELAYED_WORK详解
    Android 中多点触摸协议
    android 电容屏(四):驱动调试之驱动程序分析篇 -- FocalTech
    android 电容屏(三):驱动调试之驱动程序分析篇
    android 电容屏(二):驱动调试之基本概念篇
  • 原文地址:https://www.cnblogs.com/vintion/p/4117011.html
Copyright © 2011-2022 走看看