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啊,只不过把多个情况转化到一个里面
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int res[],b[];
int main()
{
int n,m,k,a,sum,mm,i,j;
while(scanf("%d",&n) && n>)
{
sum=;mm=;
memset(res,,sizeof(res));
for(j=,i=;i<n;i++)
{
scanf("%d %d",&a,&m);
sum=sum+a*m;
for(k=;k<m;k++)
b[j++]=a;
}
n=j;
res[]=;
for(i = ;i < n ; ++ i)
{
if(mm!=sum/) mm+=b[i];
if(mm>sum/) mm=sum/;
for( j = mm; j >=b[i] ; j--)//在这优化了,以前是遍历到0;
if(res[j-b[i]]) res[j]=;
}
for(i=sum/;!res[i];i--);
printf("%d %d\n",sum-i,i);
}
return ;
}
 

hdoj1171 Big Event in HDU的更多相关文章

  1. hdoj1171 Big Event in HDU(01背包 || 多重背包)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意 老师有一个属性:价值(value).在学院里的老师共有n种价值,每一种价值value对应着 ...

  2. [HDOJ1171]Big Event in HDU(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 许多有价值的物品,有重复.问如何将他们分成两堆,使两堆价值之差最小. 对价值求和,转换成01背包 ...

  3. HDU-1171 Big Event in HDU

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  4. Big Event in HDU

    Description Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe ...

  5. Big Event in HDU(HDU1171)可用背包和母函数求解

    Big Event in HDU  HDU1171 就是求一个简单的背包: 题意:就是给出一系列数,求把他们尽可能分成均匀的两堆 如:2 10 1 20 1     结果是:20 10.才最均匀! 三 ...

  6. 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  7. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  8. Big Event in HDU[HDU1171]

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. HDU1171——Big Event in HDU(母函数)

    Big Event in HDU DescriptionNowadays, we all know that Computer College is the biggest department in ...

随机推荐

  1. Php与Erlang的Socket通信

     一般来说网络通讯经常使用的方式有2种:文本通讯和二进制通讯. php与erlang之间实现文本通讯比較简单.这里就不做讨论,本文主要讨论的是php与erlang实现二进制通讯的实现方法.实现过程 ...

  2. jquery.dataTables动态列

    jquery.dataTables  版本1.10.7 直接上代码: 0.table <table id="popReportTable"> <thead> ...

  3. js replace全部替换的方法

    1.JS replace()方法替换变量(可以对变量进行全文替换) string.replace(new RegExp(key,'g'),"b"); 2.封装 String.pro ...

  4. xcode8 的坑 Info.plist 配置app权限

    好多更新完Xcode8 的小盆友们(我也是小盆友啦),会发现当我们调用系统功能,相册,相机,麦克风等会出现崩溃,而控制台打印出一堆乱七八糟的看不懂的东西,但是最后一句话是有用的,给出了崩溃的原因 啦, ...

  5. DOS批处理高级教程

    转载-->http://blog.csdn.net/lanbing510/article/details/7461073 前言 本教程主要引用伤脑筋版主的系列文章,同时参考引用[英雄]教程等其他 ...

  6. 〖Linux〗Ubuntu13.10,声音图标调节音量失效的解决办法

    升级Ubuntu13.10,发现声音图标不能调节音量[XUbuntu13.10发行日志]: 临时解决办法: gvim /usr/share/dbus-1/services/indicator-soun ...

  7. 【重要】新浪微博api研究

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #新浪微博api研究 ''' 3.SDK的使用规则: 1)使用微博API,需要通过用户的授权,获取用户的授权码 ...

  8. apacheBench对网站进行压力测试

    apacheBench对网站进行压力测试 分类: 学习 2014-02-19 10:35 4154人阅读 评论(1) 收藏 举报 apacheBench压力测试 Apache Benchmark下载 ...

  9. HTTP 304状态分析

       在看http log日志发现很多304状态的标识 HTTP 304: Not Modified   ###请求后读取本地缓存的文件标准解释是:Not Modified 客户端有缓冲的文档并发出了 ...

  10. HDUOJ------2492Ping pong

    Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...