Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18273    Accepted Submission(s): 6403

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

Author
lcy

A easy one ,but the question producer is so boring that he make such fucking test cases.The input is terminated with a negative integer not minus one.Beside when N equals to zero the case is also not to be processed too.

#include<stdio.h>
#include<string.h>
bool f[300000];
int v[125],m[125];
int main()
{
int N;
while (scanf("%d",&N)!=EOF)
{
if (N<0) return 0;
if (N==0) continue;
int sum=0,i,j,k,A;
for (i=1;i<=N;i++)
{
scanf("%d%d",&v[i],&m[i]);
sum+=v[i]*m[i];
}
memset(f,0,sizeof(f));
f[0]=true;
for (i=1;i<=N;i++)
for (j=1;j<=m[i];j++)
for (k=sum;k>=0;k--)
if (f[k]) f[k+v[i]]=true;
for (i=(sum+1)/2;i<=sum;i++)
if (f[i])
{
A=i;
break;
}
printf("%d %d\n",A,sum-A);
}
return 0;
}

Big Event in HDU[HDU1171]的更多相关文章

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

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

  2. HDU-1171 Big Event in HDU

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

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

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

  4. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  5. hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏

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

  6. poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)

    题目链接: id=3211">poj3211  hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...

  7. Big Event in HDU

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

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

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

  9. 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 ...

随机推荐

  1. ios 应用程序图标、启动画面、itune图标设置

    http://blog.sina.com.cn/s/blog_4cd8dd1301014hfz.html 先说说应用程序图标,一般有下面几种: Icon.png(57x57) - Homescreen ...

  2. HDOJ 1026 dfs路径保存

    #include<cstdio> #include<cstring> #include<cmath> ][]; #define inf 0xffffff int n ...

  3. Android mtk单路录音问题

    在单路录音中,有两种情况导致底层录音资源被占用的问题: 1 开启vmLog后,拨打一个电话,挂断电话.如果挂断电话后,没有关闭vmlog进程,则会导致其它AP 无法得到底层的录音资源,从而无法录音. ...

  4. 【OpenStack】OpenStack系列4之Glance详解

    下载安装 参考:http://www.linuxidc.com/Linux/2012-08/68964.htm http://www.it165.net/os/html/201402/7246.htm ...

  5. 4.在二元树中找出和为某一值的所有路径[FindPathsInBinaryTree]

    [题目]: 输入一个整数和一棵二元树.从树的根结点开始往下访问一直到叶结点所经过的所有结点形成一条路径.打印出和与输入整数相等的所有路径. 例如输入整数22和如下二元树 10              ...

  6. auto_ptr浅析(转载)

    转载自http://www.cnblogs.com/qytan36/archive/2010/06/28/1766555.html auto_ptr是C++标准库中(<utility>)为 ...

  7. Java for LeetCode 055 Jump Game

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  8. poj 2013 Symmetric Order 解题报告

    题目链接:http://poj.org/problem?id=2013 设长度非递减的字串序列为s[1]...s[n].设计递归子程序print(n),其中n为字串序号,每分析1个字串,n=n-1. ...

  9. Servlet之Cookie操作

    Java对cookie的操作比较简单,主要介绍下建立cookie和读取cookie,以及如何设定cookie的生命周期和cookie的路径问题. 1,建立一个无生命周期的cookie,即随着浏览器的关 ...

  10. Android中mesure过程详解

    我们在编写layout的xml文件时会碰到layout_width和layout_height两个属性,对于这两个属性我们有三种选择:赋值成具体的数值,match_parent或者wrap_conte ...