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

  • 相关阅读:
    vue项目中使用定时器,离开页面时清除定时器
    不能在循环中使用res.send(err);
    React使用require加载图片失败
    实验五 单元测试
    实验四 代码评审
    UML 建模工具的安装与使用
    结对编程 第二阶段
    结对编程
    GIT 代码版本管理
    结构化方法与面向对象化方法的比较
  • 原文地址:https://www.cnblogs.com/372465774y/p/2429848.html
Copyright © 2011-2022 走看看