Big Event in HDU


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

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

题目大意:有N种设备,每种设备有一个价值和数量。先要将这N种设备按总价值

尽可能的平均分给两个学院。

若不能全然平均分,则第一个学院多分一点。

问。两个学院能各能分得多少价值的设备?

思路:每种设备都有一个数量和价值,能够把每个设备都当做一件物品,比方第

一种设备有M件,价值为V则转换为有M件物品。价值都为V。这样就能转换成01

背包了。

把总价值的一半当做背包容量。求最多能装多少价值的物品。由于在尽可

能平分的基础上第一个学院要多分一些。所以结果为第一学院分得sum-dp[sum/2],

第二学院分得dp[sum/2]。

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; int V[5050],dp[250050]; int main()
{
int N,v,m,sum;
while(~scanf("%d",&N) && N>0)
{
int num = 0;
sum = 0;
memset(V,0,sizeof(V));
memset(dp,0,sizeof(dp));
for(int i = 0; i < N; i++)
{
scanf("%d%d",&v,&m);
while(m--)
{
V[num++] = v;
sum += v;
}
}
for(int i = 0; i < num; i++)
{
for(int j = sum/2; j >= V[i]; j--)
{
dp[j] = max(dp[j],dp[j-V[i]] + V[i]);
}
} printf("%d %d\n",sum-dp[sum/2],dp[sum/2]);
}
return 0;
}

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

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

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

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

  6. Big Event in HDU(01背包)

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

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

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

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

  9. hdu 01背包汇总(1171+2546+1864+2955。。。

    1171 题意比较简单,这道题比较特别的地方是01背包中,每个物体有一个价值有一个重量,比较价值最大,重量受限,这道题是价值受限情况下最大,也就值把01背包中的重量也改成价值. //Problem : ...

随机推荐

  1. linux下启动、停止tomcat,杀死tomcat进程

    1.打开终端 cd /java/tomcat 2.执行 bin/startup.sh #启动tomcat bin/shutdown.sh #停止tomcat tail -f logs/catalina ...

  2. LR性能分析随笔(一)

    一.关键词 吞吐量:对于吞吐量,单位时间内吞吐量越大,说明服务器的处理能力越好:而请求数仅表示客户端向服务器发出的请求数,与吞吐量一般成正比关系. HTTP:HTTP404表示文件或目录没有找到.有些 ...

  3. PHPExcel导入

    PHPExcel 是用来操作Office Excel 文档的一个PHP类库,可以使用它来读取.写入不同格式的电子表格 Github:https://github.com/PHPOffice/PHPEx ...

  4. No value specified for parameter1?

    我使用的是jdbcTemplate,因为忘记向list中加入参数,所以报错. 解决方案,: String sql = "select * from table where id = ?&qu ...

  5. 巧用TWaver 3D 矢量图形功能

    的确,提起TWaver,大家想到的首先是“电信拓扑图组件”.其实,由于其灵活的MVC架构.矢量化设计.方便定制等特点,TWaver可以做的还有很多.例如房地产行业常见到的“户型图”. 户型推荐是销售接 ...

  6. UVA - 12325 Zombie's Treasure Chest (分类搜索)

    题目: 有一个体积为N的箱子和两种数量无限的宝物.宝物1的体积为S1,价值为V1:宝物2的体积为S2,价值为V2.输入均为32位带符号整数.计算最多能装多大价值的宝物,每种宝物都必须拿非负整数个. 思 ...

  7. 每日命令:(11)nl

    nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...

  8. LINUX-SWAP文件系统

    mkswap /dev/hda3 创建一个swap文件系统 swapon /dev/hda3 启用一个新的swap文件系统 swapon /dev/hda2 /dev/hdb3 启用两个swap分区

  9. 2.5.5 基本的 I/0 重定向

        标准输入/输出(standard I/O)可能是软件设计原则里最重要的概念了.这个概念就是:程序应该有数据的来源端.数据的目的端以及报告问题的地方,它们分别被称为标准输入(standard i ...

  10. JS权威指南笔记1

    1.JavaScript数据类型可分为两种:原始类型和对象类型.原始类型下又包括数字.字符串和布尔值,以及null和undefined这两个特殊的:对象是属性的集合,且每个属性都有自己的"名 ...