zoukankan      html  css  js  c++  java
  • 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 }
     
  • 相关阅读:
    30分钟全面解析-SQL事务+隔离级别+阻塞+死锁
    apache 不执行PHP,显示代码
    ERROR 1406 : Data too long for column 解决办法
    apache下php无法解析直接显示源代码解
    win7系统,apache2.2下添加PHP5的配置详解
    apache 添加到windows服务
    升级3.2.3后 could not find driver
    Windows server 2008搭建php运行环境
    MySQL 5.6 for Windows 解压缩版配置安装
    Linux vi/vim替换命令的使用说明[转]
  • 原文地址:https://www.cnblogs.com/lovychen/p/3230129.html
Copyright © 2011-2022 走看看