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. java web下串口通讯

       最近在做java串口通讯,主要是用个人电脑通过串口从RS485读取数据,并通过crc循环冗余校验,把接收正确的数据解析,插入数据库mysql,并用SSH技术把数据库数据以表格以及图表形式显示   ...

  2. Swift高速入门之函数

    函数 看一个函数的样例: func addNumbers( let a:Int,let b:Int)->Int{ return a+b; } 实现两个数相加.函数必须以func开头,后面是函数名 ...

  3. from会存在潜在的陷阱

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #from会存在潜在的陷阱 #from时,可能会遇到相同变量名,变量会被悄悄覆盖掉, #但是import语句不 ...

  4. map函数原理

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #map函数 #map函数会对一个序列对象中的每一个元素应用被传入的函数,并返回一个包含了所有函数调用结果的一 ...

  5. IDEA删除项目

    IDEA没有eclipse的右键直接在磁盘delete整个项目的功能,使用IDEA删除项目需要按照如下步骤: step1:右击项目——>Remove Module 之后会出现提示框如下: 意思是 ...

  6. Git恢复之前版本的两种方法reset、revert(图文详解)

    一.问题描述在利用github实现多人合作程序开发的过程中,我们有时会出现错误提交的情况,此时我们希望能撤销提交操作,让程序回到提交前的样子,本文总结了两种解决方法:回退(reset).反做(reve ...

  7. java 运行时环境和编译器环境

    必须要保证运行环境高于编译环境 1.编译器的环境设置 单击项目右键-> Properties -> Java Compiler -> 5或6 如果编译器的环境高于运行时环境会报错. ...

  8. Python 绘图库的使用:matplotlib

    Matplotlib 官方API地址:https://matplotlib.org/ 例子: import matplotlib.pyplot as plt num_list=[1.5,0.6,7.8 ...

  9. WordPress 博客文章中google adsense广告展示方法之一

    http://log.medcl.net/item/2011/08/diving-into-elasticsearch-4-installation-and-configuration/ 看到这个网站 ...

  10. 记一次400错误引发的血案(URL中特殊符号的转义/400 bad request错误)

    django+nginx+uwsgi部署的站点访问某个URL时发生了400 bad request的错误,而使用django自带的开发版的web server时没有遇到此问题.初步判断是nginx或u ...