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. Lucene4.3开发之分词器总结

    Lucene4.3开发之分词器总结 http://java.chinaitlab.com/tools/940011.html

  2. Stanford机器学习---第七讲. 机器学习系统设计

    原文:http://blog.csdn.net/abcjennifer/article/details/7834256 本栏目(Machine learning)包括单参数的线性回归.多参数的线性回归 ...

  3. FOJ 1205

    Problem 1205 小鼠迷宫问题 Accept: 522    Submit: 1679 Time Limit: 1000 mSec    Memory Limit : 32768 KB Pro ...

  4. django静态文件查找逻辑

    最近被django的静态文件配置整疯了. 决定直捣黄龙,看看底层代码: 首先用manage finstatic xxxx.js 看看处理逻辑,发现主要在:C:\Python27\Lib\site-pa ...

  5. CentOS 初始化时的分区

    /            ext3    8189   固定大小 空          swap    509   固定大小 /boot     ext3     100   固定大小 /home   ...

  6. 【云计算】docker run详解

    Docker学习总结之Run命令介绍 时间 2015-01-21 17:06:00                                               博客园精华区       ...

  7. Linux下提取IP至文件

    ifconfig | grep 'inet[^6]' | sed 's/^\s*//g' | cut -d ' ' -f2 > ips.txt 排除127开头的IP: ifconfig | gr ...

  8. css 之盒子模型

    display: none  inline   block float :none   right   left clear  left   right  both    清除浮动  是清楚它之前的左 ...

  9. Unsupported major.minor version 51.0 在配置/运行Maven工程时,JDK与Maven所引用的jdk版本不一致

    在配置Maven工程,部署到tomcat服务器运行的过程中,遇到如下错误: "Unsupported major.minor version 51.0 " 错误原因是由于maven ...

  10. Catch That Cow(poj 3278)

    给定两个整数n和k 通过 n+1或n-1 或n*2 这3种操作,使得n==k 输出最少的操作次数 //广搜,a是队列,step记录步数,vis记录哪些数被搜到过 #include<cstdio& ...