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

  • 相关阅读:
    markdown语法
    基于Vue 使用threejs导入gltf动画模型
    创建Vue项目
    一个简单的特效
    网页五--html插入表格
    网页四--按钮反应
    网页三
    简单的页面
    一个能实现超链接的最简单程序
    计算机基本配置和作用
  • 原文地址:https://www.cnblogs.com/372465774y/p/2429848.html
Copyright © 2011-2022 走看看