zoukankan      html  css  js  c++  java
  • HDU 1085 Holding BinLaden Captive!

    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

    #include

    开始WA了,郁闷了一会儿,结果发现是数组开小了,5+2+1我居然等于7了,郁闷

     <iostream>
    #include <cstdio>
    #include <string.h>
    using namespace std;
    #define N 8003
    int a[N],b[N];
    int main()
    { int i,j,k,m;
     int r[3],s[3]={1,2,5};
     while(scanf("%d%d%d",&r[0],&r[1],&r[2]),r[0]||r[1]||r[2])
        {  memset(a,0,sizeof(a));
           memset(b,0,sizeof(b));
           m=r[0]+r[1]*2+r[2]*5;
            for(i=0;i<=r[0];i++)
               a[i]=b[i]=1;
         for(k=1;k<=2;k++)
         {
           for(j=1;j<=r[k];j++)
             for(i=0;i+j*s[k]<=m;i++)
                {a[i+j*s[k]]+=b[i];}
             for(i=0;i<=m;i++)
                  b[i]=a[i];
         }

        for(i=0;i<=m;i++)
           if(!a[i])
            break;
        printf("%d\n",i);

        }
     return 0;
    }

  • 相关阅读:
    PPT能输英文不能输汉字
    常用HTML正则表达式
    Log4j使用总结
    JsonConfig过滤对象属性
    打开”我的电脑“,不显示”共享文档“和”我的文档“,解决办法。(windows XP系统)
    错误org.hibernate.LazyInitializationException
    Tomcat中实现IP访问限制
    windows server 2008中让AD域中的普通用户可以 远程登录 域控服务器。
    ibatis简介及 like查询
    IE访问页面的时候,受限制的解决方案。
  • 原文地址:https://www.cnblogs.com/372465774y/p/2429848.html
Copyright © 2011-2022 走看看