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

  • 相关阅读:
    Qt-char类型的字符串转换成数字和数字转换成char类型字符串
    Qt-label显示的汉字自动换行
    Qt-Libmodbus
    Linux-uboot命令之EXT格式文件系统操作命令
    Linux-uboot命令之FAT格式文件系统操作命令
    Linux-使用uboot命令将Linux镜像和设备树文件下载到EMMC中
    Linux-在uboot中更新uboot(包含SD卡和EMMC)
    Linux-使用uboot命令将Linux镜像和设备树文件下载到DRAM中
    Qt-QCustomPlot(画坐标系统)的简单操作
    Qt-QTableView的简单使用
  • 原文地址:https://www.cnblogs.com/372465774y/p/2429848.html
Copyright © 2011-2022 走看看