• Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂


    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
     1 #include<stdio.h>
     2 #include<string.h>
     3 #include<math.h>
     4 
     5 int n1[8005],n2[8005];
     6 int num[4],p[4],sum;
     7 
     8 void fuction()
     9 {
    10     memset(n1,0,sizeof(n1));
    11     memset(n2,0,sizeof(n2));
    12     n1[0]=1;/*注意,0面值也要算在内,不然后面if(n1[j])不通过,因为假如要计算1面币是否存在,1=1+0,所以0面币要存在*/
    13     int i,j,k;
    14     for(i=1;i<=3;i++)//1 2 5硬币
    15     {
    16         for(j=0;j<=sum;j++)//产生的面额
    17             for(k=0;k<=num[i]&&k*p[i]+j<=sum;k++)//个数,判断是否超出sum
    18                 if(n1[j])
    19                     n2[k*p[i]+j]=1;/*没有明白为什么要赋值1,怎么不是他的个数??*/
    20         for(j=0;j<=sum;j++)
    21         {
    22             n1[j]=n2[j];
    23             n2[j]=0;
    24         }
    25     }
    26 }
    27 int main()
    28 {
    29     p[1]=1,p[2]=2,p[3]=5;
    30     int i;
    31     while(~scanf("%d%d%d",&num[1],&num[2],&num[3])&&(num[1]||num[2]||num[3]))
    32     {
    33         sum=p[1]*num[1]+p[2]*num[2]+p[3]*num[3];
    34         fuction();
    35         for(i=0;i<=sum+1;i++)
    36             if(n1[i]==0)
    37             {
    38                 printf("%d
    ",i);
    39                 break;
    40             }
    41     }
    42     return 0;
    43 }
  • 相关阅读:
    2014-9-思杨的缺点
    2014-8-9月杂记
    2014-7-31 思杨在老家想我们
    生日。金鼎轩吃饭;亿旺中影看《后会无期》。
    2014-7-5~6 秦皇岛之旅,带思杨看大海
    2014-6-23 去未来幼儿园玩————————
    2014-6-15 思杨的成长是全家人的责任。
    2014-6-14 思杨跳抓钱舞---疾驰的扭扭车和思杨司机
    2014-6-7 带思杨去西三旗儿童乐园玩-----思杨晕车了
    springboot学习之一
  • 原文地址:https://www.cnblogs.com/a1225234/p/4513382.html
Copyright © 2020-2023  润新知