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

    背包模版:

    Big Event in HDU

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 17006    Accepted Submission(s): 5991


    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 <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 
     5 using namespace std;
     6 
     7 int v;
     8 int dp[333333];
     9 
    10 void zpack(int *a,int c,int w)
    11 {
    12     for(int i=v;i>=c;i--)
    13         a[i]=max(a[i],a[i-c]+w);
    14 }
    15 
    16 void cpack(int *a,int c,int w)
    17 {
    18     for(int i=c;i<=v;i++)
    19         a[i]=max(a[i],a[i-c]+w);
    20 }
    21 
    22 void multipack(int *a,int c,int w,int m)
    23 {
    24     if(c*m>=v)
    25     {
    26         cpack(a,c,w);
    27         return ;
    28     }
    29 
    30     int k=1;
    31     while(k<m)
    32     {
    33         zpack(a,k*c,k*w);
    34         m-=k;
    35         k*=2;
    36     }
    37 
    38     zpack(a,m*c,m*w);
    39 }
    40 
    41 int c[100];
    42 int m[100];
    43 
    44 int main()
    45 {
    46     int n;
    47 while(scanf("%d",&n)&&n>0)
    48 {
    49     memset(c,0,sizeof(c));
    50     memset(m,0,sizeof(m));
    51     memset(dp,0,sizeof(dp));
    52 
    53     int sum=0;
    54     for(int i=0;i<n;i++)
    55     {
    56         scanf("%d%d",&c[i],&m[i]);
    57         sum+=c[i]*m[i];
    58     }
    59     v=sum/2;
    60     for(int i=0;i<n;i++)
    61         multipack(dp,c[i],c[i],m[i]);
    62 
    63     printf("%d %d\n",sum-dp[v],dp[v]);
    64 
    65 }
    66 
    67     return 0;
    68 }
  • 相关阅读:
    测试网络
    测试
    Centos6.6中VIM的编辑、退出与保存
    IP
    2018.12.24 课程更新内容到第五章 渗透测试 第4、5节
    利用GRC进行安全研究和审计 – 将无线电信号转换为数据包(转)
    我的翻译--一个针对TP-Link调试协议(TDDP)漏洞挖掘的故事
    我的翻译--针对Outernet卫星信号的逆向工程
    Sulley安装手记
    乘用车黑客手册(译)
  • 原文地址:https://www.cnblogs.com/CKboss/p/3102820.html
Copyright © 2011-2022 走看看