Big Event in HDU

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
 
Wrong Answer
刚开始的RE和WA,一看原因是没有处理总数和DP数组太小,之后还是WA,竟然是没看题,以为是-1结束,完全不知道是负数结束。。。
 
Answer
输入是价值和数量,如果数量不是1,那么在放入数组的时候,需要用一个循环,把相应数量的价值都放进数组。
目的是要把这些东西分成价值最相近的两堆,那就先求出总价值,除以2,因为当两个都是半数的时候最接近,但是由于物品的价值不同,不一定能恰好分成两堆价值相同,就用半价值作为背包容量,求出最多能放入多少,总量减去这个最多的价值,就是另一堆的价值,输出要先大后小。
 
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
#define msd memset(dp,0,sizeof(dp))
using namespace std;
//#define LOCAL
int dp[];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
//freopen("out.txt","w",stdout);
#endif // LOCAL
ios::sync_with_stdio(false);
int n;
while(cin>>n&&n>)
{
int sum=;
vector<int>v;
v.clear();
for(int i=;i<n;i++)
{
int t1,t2;
cin>>t1>>t2;
while(t2)
{v.push_back(t1);t2--;sum+=t1;}
}
int m=sum/;
msd,n=v.size();
for(int i=;i<n;i++)
{
for(int j=m;j>=v[i];j--)
{
dp[j]=max(dp[j],dp[j-v[i]]+v[i]);
}
}
printf("%d %d\n",sum-dp[m],dp[m]);
}
return ;
}

HUD 1171 Big Event in HDU(01背包)的更多相关文章

  1. 1171 Big Event in HDU 01背包

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...

  2. HDU 1171 Big Event in HDU(01背包)

    题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...

  3. hdu 1171 Big Event in HDU (01背包, 母函数)

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

  4. HDU 1171 Big Event in HDU(01背包)

    题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++ ...

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

  6. HDU 1171 Big Event in HDU dp背包

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

  7. HDU - 1171 Big Event in HDU 多重背包

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

  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. hdu1171Big Event in HDU(01背包)

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

随机推荐

  1. 图解Javascript引用类型之数组

    以图说事明理,恰当时候会事半功陪.今天我就尝试着用图的方式讲讲“JavaScript引用类型之数组”.望更多童鞋给我反馈! 好东西分享给大家,但要尊重事实!!!因此特别说明:本图非我本人亲自所作,乃我 ...

  2. Unicode(UTF&UCS)深度历险

    Unicode(UTF&UCS)深度历险 计算机网络诞生后,大家慢慢地发现一个问题:一个字节放不下一个字符了!因为需要交流,本地化的文字需要能够被支持. 最初的字符集使用7bit来存储字符,因 ...

  3. opencv中的vs框架中的Blob Tracking Tests的中文注释。

    经过2天的努力终于算是大概弄清楚了opencv中的vs框架是大概是如何工作的了,下面贴一下我自己写的代码注释.非常详细.对初学者有帮助.尤其详细分析了RunBlobTrackingAuto()函数,在 ...

  4. 基于Hadoop开发网络云盘系统客户端界面设计初稿

    基于Hadoop开发网络云盘系统客户端界面设计初稿 前言: 本文是<基于Hadoop开发网络云盘系统架构设计方案>的第二篇,针对界面原型原本考虑有两个方案:1.类windows模式,文件夹 ...

  5. Google开源的Deep-Learning项目word2vec

    用中文把玩Google开源的Deep-Learning项目word2vec   google最近新开放出word2vec项目,该项目使用deep-learning技术将term表示为向量,由此计算te ...

  6. jquery简单封装

    对Raphael画图标的一个jquery简单封装 公司要做一个项目的demo,要求地图上可以插红旗,所以就用到了Raphael. 因为是个demo,所以地图就用了一张图片,效果如下: 所以为了更好的封 ...

  7. 初探原生js根据json数据动态创建table

    初探原生js根据json数据动态创建table 小生以实习生的职位进入了一家非纯软件的公司做asp.net开发,大半个月下来发现公司里居然没有前端工程师,这令我很诧异,跟着公司做项目,发现前端后台没有 ...

  8. CF 332A Down the Hatch! 超级水题。。不过题目太长了

    A. Down the Hatch! time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  9. ORM查询语言(OQL)简介高级篇

    ORM查询语言(OQL)简介--高级篇:脱胎换骨 在写本文之前,一直在想文章的标题应怎么取.在写了<ORM查询语言(OQL)简介--概念篇>.<ORM查询语言(OQL)简介--实例篇 ...

  10. spring得到实例和new一个实例,哪个快?

    spring配置的bean是默认单例,那么在程序中,得到一个实例一定比创建一个实例的速度快,也更加省资源.今天实际测试的时候发现,new 一个对象比spring得到一个对象快多了.后面自己又加了个单例 ...