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

    Holding Bin-Laden Captive!

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 11317    Accepted Submission(s): 5064


    Problem Description
    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
     
    Author
    lcy
     
        这个题的是用母函数写的,可能复杂了些~~~一会儿研究下,更简单的解法!
    #include <stdio.h>
    #include <stdlib.h>
    
    int  temp1[10000], temp2[10000];
    
    int main(int argc, char *argv[])
    {
        int num_1, num_2, num_5, i, j;
        int a[1005], b[2005], c[5005];
        while( (scanf( "%d%d%d", &num_1, &num_2, &num_5 )!= EOF)&&( num_1||num_2||num_5 ) )
        {
               memset(a, 0, 1005 * sizeof(int));
               memset(b, 0, 2005 * sizeof(int));
               memset(c, 0, 5005 * sizeof(int));
               memset(temp1, 0,  10000 * sizeof(int));
               memset(temp2, 0,  10000 * sizeof(int));
               //printf( "0 0 0\n" );     
               for( i = 0; i <= num_1; i++ )
                    a[i] = 1;
               for( i = 0; i <= num_2 * 2; i += 2 )
                    b[i] = 1;
               for( i = 0; i <= num_5 * 5; i += 5 )
                    c[i] = 1;
                    
               /*for( i = 0; i <= num_1; i++ )
                    printf( "%d ", a[i] );
               printf( "\n" );*/
               
               
               
               for( i = 0; i <= num_1; i++ )
                    for( j = 0; j <= num_2 * 2 ; j += 2 )
                         temp1[i+j] += a[i] * b[j];
               
               for( i = 0; i <= 3000; i++ )
                    for( j = 0; j <= num_5 * 5; j += 5 )
                         temp2[i+j] += temp1[i] * c[j];
               for( i = 0; i < 10000; i++ )
                    if( temp2[i] == 0 )
                        break;
               printf( "%d\n", i );    
        }
      
     // system("PAUSE");    
      return 0;
    }
  • 相关阅读:
    七种数据类型
    js字符串解析成数字
    html节点操作与事件
    form表单的默认提交行为
    CSS中的各种width(宽度)
    Javascript读写CSS属性
    ECMAScript6新特性之Reflect
    ECMAScript6新特性之String API
    ECMAScript6新特性之Array API
    判断Javascript对象是否为空
  • 原文地址:https://www.cnblogs.com/yizhanhaha/p/3075237.html
Copyright © 2011-2022 走看看