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. tomcat配置APR

    转载 Windows下配置Tomcat的Apr(包括Https)  tomcat bio nio apr 模式性能测试与个人看法 一.windows 下配置Tomcat的APR: 1.到Apache  ...

  2. 【转】计算Java List中的重复项出现次数

    本文演示如何使用Collections.frequency和Map来计算重复项出现的次数.(Collections.frequency在JDK 1.5版本以后支持) package com.qiyad ...

  3. python单元测试unittest框架

    环境:PyCharm 2016.2 + python 3.5 待测试的类:(Widget.py) 测试类:(Auto.py) 测试结果: 总结:1.第一步:先写好测试类2.第二步:导入unittest ...

  4. H5基本标签

  5. String的非空判断、Integer的非空判断、list的大小判断,对象的非空判断

    1.String的非空判断. StringUtils.isNotEmpty(String str); 2.Integer的非空判断. null != Integer ; 3.list的大小判断. li ...

  6. Cocopods Search失败的坑

    最近看了下如何使用cocopods来制作自己的公有库,然后果断的按照教程做了一遍,然后提交审核.完成之后意外的发现使用pod search xxx的时候报了一大堆的日志出来,pod的其他功能可以使用, ...

  7. JS中的原型规则与原型链

    1. 原型规则 A. 所有的引用类型(数组.对象.函数),都具有对象特性,即可自由扩展属性: var arr = []; arr.a = 1;B. 所有的引用类型(数组.对象.函数),都有一个_pro ...

  8. Spring Cloud 微服务入门(二)--Spring Cloud 架构

    Spring Cloud整体核心架构:Rest服务,在Spring Cloud配置过程中,都是遵循Rest风格规范,在Rest处理中,必不可少两个对象端:服务的提供者(provider)和服务消费者( ...

  9. TinyMCE插件:Filemanager [4.x-6.x] 文件名统一格式化

    上传图片程序(filemanager/upload.php) 在if (!empty($_FILES) && $upload_files)中上传图片时,在文件正式上传至服务器前,有一次 ...

  10. 【转载】 旧版本Microsoft Office正在配置解决方法

    原文:https://blog.csdn.net/sinat_37215184/article/details/81053931 在运行Microsoft Office 2010等旧版本的Office ...