• hdoj1171 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): 18376    Accepted Submission(s): 6430


    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
     类似于zb的生日啊,一次AC啊,只不过把多个情况转化到一个里面
     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cstring>
     4 #include<algorithm>
     5 using namespace std;
     6 int res[250010],b[5010];
     7 int main()
     8 {
     9     int n,m,k,a,sum,mm,i,j;
    10     while(scanf("%d",&n) && n>0)
    11     {
    12         sum=0;mm=0;
    13         memset(res,0,sizeof(res));
    14         for(j=0,i=0;i<n;i++)
    15         {
    16         scanf("%d %d",&a,&m);
    17         sum=sum+a*m;
    18         for(k=0;k<m;k++)
    19            b[j++]=a;
    20         }
    21         n=j;
    22          res[0]=1;
    23         for(i = 0 ;i < n ; ++ i)
    24         {
    25             if(mm!=sum/2) mm+=b[i];
    26             if(mm>sum/2) mm=sum/2;
    27             for( j = mm; j >=b[i] ; j--)//在这优化了,以前是遍历到0;
    28             if(res[j-b[i]]) res[j]=1;
    29          }
    30        for(i=sum/2;!res[i];i--);
    31         printf("%d %d
    ",sum-i,i);
    32     }
    33     return 0;
    34 }
     
  • 相关阅读:
    linux进程间通信-共享内存
    where和having子句的区别
    多进程和多线程的区别(转载)
    android手机调试时不能打印Logcat日志信息
    来源不清,随笔
    转载
    C语言和Lua的交互
    python常用代码笔记
    python入门问题(windows7+python35+pycharm)
    常用matlab代码笔记
  • 原文地址:https://www.cnblogs.com/lovychen/p/3230129.html
Copyright © 2020-2023  润新知