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. poj 2195 Going Home(最小费最大流)

    poj 2195 Going Home Description On a grid map there are n little men and n houses. In each unit time ...

  2. java手动加载jar

    @RequestMapping("/testJar") public @ResponseBody String exteriorJar(int ys, int csd,int jg ...

  3. nmon与nmonanalyser系统性能分析

    nmon与nmonanalyser系统性能分析(图表) - [系统架构] 2011-05-15 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://www.blogbus.c ...

  4. scala class和object,trait的区别

    Scala类 1 2 3 4 5 6 7 8 9 10 11 12 13 class Counter {   private var value = 0 // 必须初始化字段   def increm ...

  5. 关于 C# HttpClient的 请求

    Efficiently Streaming Large HTTP Responses With HttpClient Downloading large files with HttpClient a ...

  6. PHP中的密码加密的解决方案

    层出不穷的类似事件对用户会造成巨大的影响,因为人们往往习惯在不同网站使用相同的密码,一家“暴库”,全部遭殃 一般的解决方案 1.将明文密码做单向hash $password = md5($_POST[ ...

  7. Codeigniter base_url() 返回的怎么是ip地址

    本篇文章由:http://xinpure.com/codeigniter-base-url-to-return-what-is-an-ip-address/ 简单说说情况 虽然也是有一段时间没有用过 ...

  8. [译]为什么Vue不支持templateURL

    原文链接 Vue的新用户最常问的一个问题,特别是以前使用Angular的用户,是"我可以使用" templateURL吗?这个问题我回答过很多次,现在写一个统一回复. 在Angul ...

  9. Everything:速度最快的文件名搜索工具

    http://xbeta.info/everything-search-tool.htm Everything(官网|中文主页|教程)是速度最快的文件名搜索软件.其速度之快令人震惊,百G硬盘几十万个文 ...

  10. linux内核线程,进程,线程

    http://blog.csdn.net/dyllove98/article/details/8917197 Linux对于内存的管理涉及到非常多的方面,这篇文章首先从对进程虚拟地址空间的管理说起.( ...