Big Event in HDU

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 27961    Accepted Submission(s): 9847

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
 

题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=1171

题目大意:有n种物品,价值为vi的有mi个,如今要买两份。要求第一份物品总价值大于等于第二份,且两份物品总价值的差最小

题目分析:多重背包问题。递减枚举价值,一旦当前价值超过了总价值的一半,计算差值取最小

#include <cstdio>
int m[55], v[55]; int main()
{
int n;
while(scanf("%d", &n) != EOF && n > 0)
{
int sum = 0;
for(int i = 0; i < n; i++)
{
scanf("%d %d", &v[i], &m[i]);
sum += v[i] * m[i];
}
int mi = sum, ans = v[0];
for(int i = 0; i < n; i++)
for(int j = sum; j >= v[i]; j--)
for(int k = 0; k <= m[i]; k++)
if(j >= k * v[i])
if(k && j % (k * v[i]) == 0 && j * 2 >= sum && 2 * j - sum < mi)
{
mi = 2 * j - sum;
ans = j;
}
printf("%d %d\n", ans, sum - ans);
}
}

HDU 1171 Big Event in HDU (多重背包变形)的更多相关文章

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

  2. HDU 1171 Big Event in HDU (多重背包)

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

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

  4. 题解报告:hdu 1171 Big Event in HDU(多重背包)

    Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...

  5. HDU 1171 Big Event in HDU(多重背包)

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

  6. hdu 1171 Big Event in HDU(多重背包+二进制优化)

    题目链接:hdu1171 思路:将多重背包转为成完全背包和01背包问题,转化为01背包是用二进制思想,即件数amount用分解成若干个件数的集合,这里面数字可以组合成任意小于等于amount的件数 比 ...

  7. HDU 1171 Big Event in HDU dp背包

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

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

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

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

随机推荐

  1. WebHeaderCollection类

    .net添加http报头 string[] allKeys = WebHeaderCollection.AllKeys; for (int i = 0; i < allKeys.Length; ...

  2. [SVN技巧]代码提交中遇到的两个问题及其解决方案

    前言 SVN在使用的过程中会遇到各种各样的问题,小黑在最近的使用中,遇到如下的两个问题,这里贴出来供大家参考 问题记录 SVN在源码仓库中不存在,导致无法删除和上传 问题提示: Working cop ...

  3. python安装模块的时候报错error: command 'gcc' failed with exit status 1

    [情况] 在写Python代码的时候,需要用到psutil模块,需要安装. 但是在安装时,报错:error: command 'gcc' failed with exit status 1 [解决步骤 ...

  4. Ubuntu下安装Sublime Text3

    1. 下载软件 Ctrl+Alt+T 调出命令窗口执行下面命令下载安装包: sudo add-apt-repository ppa:webupd8team/sublime-text-3 2. 更新软件 ...

  5. Effective C++笔记(五):实现

    参考:http://www.cnblogs.com/ronny/p/3754755.html 条款26:尽可能延后变量定义式的出现时间 有些对象,你可能过早的定义它,而在代码执行的过程中发生了导常,造 ...

  6. 【hdoj_1865】1sting(递推+大数)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1865 本题的关键是找递推关系式,由题目,可知前几个序列的结果,序列长度为n=1,2,3,4,5的结果分别是 ...

  7. PHP获取机器mac代码

    废话不多话,直接上代码 <?php class GetMac { public $result = array(); public $macAddrs = array(); //所有mac地址 ...

  8. 【PAT】1010. 一元多项式求导 (25)

    1010. 一元多项式求导 (25) 设计函数求一元多项式的导数.(注:xn(n为整数)的一阶导数为n*xn-1.) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数 ...

  9. mysql字符编码相关

    mysql> show variables like '%character%'; +--------------------------+--------------------------- ...

  10. Good Bye 2014 F - New Year Shopping

    F - New Year Shopping 对于一种特殊的不可逆的dp的拆分方法.. 也可以用分治写哒. #include<bits/stdc++.h> #define LL long l ...