zoukankan      html  css  js  c++  java
  • 杭电1171 Big Event in HDU

    Problem Description
    Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.
    The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is N (0<N<1000) kinds of facilities (different value, different kinds).
     
    Input
    Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --corresponding number of the facilities) each. You can assume that all V are different.
    A test case starting with a negative integer terminates input and this test case is not to be processed.
     
    Output
    For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
     
    Sample Input
    2 10 1 20 1 3 10 1 20 2 30 1 -1
     
    Sample Output
    20 10 40 40
     
    Author
    lcy
     
        母函数!
     1 #include <stdio.h>
     2 #include <string.h>
     3 
     4 int c1[250001], c2[250001];
     5 
     6 int main()
     7 {
     8     int n, v[55], num[55], i, sum, j, k, len;
     9     while( (scanf( "%d", &n ) != EOF)&&(n > 0) )
    10     {
    11         memset(v,0,sizeof(v));
    12         memset(num,0,sizeof(num));
    13         memset(c1,0,sizeof(c1));
    14         memset(c2,0,sizeof(c2));
    15         sum = 0;
    16         for( i = 0; i < n; i++ )
    17         {
    18             scanf( "%d%d",&v[i], &num[i] );
    19             sum += v[i] * num[i];
    20         }
    21         len = v[0] * num[0];
    22         for( i = 0; i <= len; i += v[0] )
    23             c1[i] = 1;
    24         for( i = 1; i < n; i++ )
    25         {
    26             for( j = 0; j <= len; j++  )
    27                 for( k = 0; k <= v[i]*num[i]; k += v[i] )
    28                     c2[j+k] += c1[j];
    29             len = len + v[i]*num[i];
    30             for( j = 0; j <= len; j++ )
    31             {
    32                 c1[j] = c2[j];
    33                 c2[j] = 0;
    34             }
    35         }
    36         if( n == 1 )
    37         {
    38             printf( "%d %d\n", v[0]*num[0]-v[0]*(num[0]/2),v[0]*(num[0]/2) );
    39         }
    40         else{
    41             for( i = sum/2; i <= len; i++ )
    42                 if( c1[i] != 0 )
    43                     break;
    44             i = (i >= (sum-i)) ? i : (sum-i);
    45             printf( "%d %d\n",i, sum-i );
    46         }
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    hdu1006
    矩阵快速幂计算hdu1575
    MATLAB逻辑函数
    pair类型
    MATLAB基础操作符与数据格式显示
    MATLAB矩阵基础运算
    状态压缩DP常遇到的位运算
    HDU1565方格取数
    C语言的数组名和对数组名取地址
    ubunut 12.04 (64bit) android编译环境搭建
  • 原文地址:https://www.cnblogs.com/yizhanhaha/p/3086608.html
Copyright © 2011-2022 走看看