Big Event in HDU

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

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

题意:航电要分校区,要把设备尽可能的等分,给出不同设备的价值和数量。尽可能的等分,其实可以转化为一个最大价值是所有设备总价一半的背包里面最大可以放的物品价值总和,这样算出来的是较小的那一组,或者是和另一组价值相等,另一组只要所有设备总价值减去这一组就是了。最后的输入结束有点坑,测试数据里面不一定是-1.。。。。。。

 #include<bits/stdc++.h>
using namespace std;
int dp[],v[];
int main() {
int n;
while(~scanf("%d",&n)&&n>)
{
memset(dp,,sizeof(dp));
memset(v,,sizeof(v));
int sum=,l=;
for(int i=;i<n;i++)
{
int a,b;
scanf("%d %d",&a,&b);
while(b--)
{
v[l++]=a;//价值
sum+=a;
}
} for(int i=;i<l;i++)
{
for(int j=sum/;j>=v[i];j--)//因为要分成两组价值相近的,所以背包的总价值
{ //直接设成全部物品总价值的一半,因为这里时从一半的时候
dp[j]=max(dp[j],dp[j-v[i]]+v[i]);//向下递减的,所以最后dp[sum/2]里面的
} //存的就是较小的那一组
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}

hdu1171Big Event in HDU(01背包)的更多相关文章

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

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

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

  3. 1171 Big Event in HDU 01背包

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

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

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

  5. Big Event in HDU(01背包)

    /* 题意: 输入一个数n代表有n种物品, 接下来输入物品的价值和物品的个数: 然后将这些物品分成A B 两份,使A B的价值尽可能相等也就是尽量分的公平一些,如果无法使A B相等,那么就使A多一些: ...

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

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

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

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

  8. HDU1171--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. 6.spring:AOP(注解)

     spring Aop AOP面向切面编程,与OOP面向对象编程相辅相成 AOP中最基本的单元是切面 问题: 代码混乱:越来越多的业务需求(日志&验证)加入后,原有的业务方法急剧膨胀,每个方法 ...

  2. HDU 1885 Key Task (带门和钥匙的迷宫搜索 bfs+二进制压缩)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1885 Key Task Time Limit: 3000/1000 MS (Java/Others)  ...

  3. 【Git】Git使用小结

    Git与SVN及TFS这类传统的版本管理的区别: 本地机器也会有分支.代码库的概念 SVN常用的做法是每次写一些代码就提交到仓库,但是Git是先提交到本地(commit),然后当本地有个稳定的版本的时 ...

  4. C语言输入输出函数总结

    常见函数: FILE *p char ch char buf[max] fopen("filename","ab")//打开名为filename的文件并返回一个 ...

  5. meta的随堂笔记

    Meta标签与搜索引擎优化(SEO) 概要 通常所说的meta标签,是在Html网页源代码中的一个重要的html标签.meta标签用来描述一个html网页文档的属性,例如作者.日期和时间.网页描述.关 ...

  6. 纯js轮播图练习-1

    偶尔练习,看视频自己学着做个简单的纯JS轮播. 简单的纯js轮播图练习-1. 样子就是上面图片那样,先不管好不好看,主要是学会运用和理解轮播的原理 掌握核心的理论知识和技术的操作,其他的都可以在这个基 ...

  7. IO流之字节流

    IO流分类 按照数据流向 输入流:从外界(键盘.网络.文件…)读取数据到内存 输出流:用于将程序中的数据写出到外界(显示器.文件…) 数据源 目的地 交通工具 按照数据类型 字节流:主要用来处理字节或 ...

  8. 应用性能管理(APM, Application Performance Management)

    当下成熟的互联网公司都建立有从基础设施到应用程序的全方位监控系统,力求及时发现故障进行处理并为优化程序提供性能数据支持,降低整体运维成本.国内外商业的APM有Compuware.iMaster.博睿B ...

  9. Spring quantz--定时任务调度工具

    1.在xml中交给spring管理的一些类 <bean id="cancelOrderJobDetail" class="org.springframework.s ...

  10. python基础 - 字符串与列表的基本操作方法

    # v = 11# data = v.bit_length()# print(data) # a = 'ABCDEFGHIJK'# print(a[0])# print(a[10]) # print( ...