HDU 1171 Big Event in HDU (多重背包变形)
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
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).
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.
time, you should guarantee that A is not less than B.
2
10 1
20 1
3
10 1
20 2
30 1
-1
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 (多重背包变形)的更多相关文章
- 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 ...
- HDU 1171 Big Event in HDU (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 ...
- 题解报告:hdu 1171 Big Event in HDU(多重背包)
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...
- HDU 1171 Big Event in HDU(多重背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- hdu 1171 Big Event in HDU(多重背包+二进制优化)
题目链接:hdu1171 思路:将多重背包转为成完全背包和01背包问题,转化为01背包是用二进制思想,即件数amount用分解成若干个件数的集合,这里面数字可以组合成任意小于等于amount的件数 比 ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
- 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 ...
- HDU 1171 Big Event in HDU(01背包)
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...
随机推荐
- python近期遇到的一些面试问题(三)
python近期遇到的一些面试问题(三) 整理一下最近被问到的一些高频率的面试问题.总结一下方便日后复习巩固用,同时希望可以帮助一些朋友们. 前两期点这↓ python近期遇到的一些面试问题(一) p ...
- Class.this 和 this 的有什么不同
转载:http://www.cnblogs.com/liwei45212/archive/2013/04/17/3026364.html 在阅读Java代码的時候 我们时会看到Class.this的使 ...
- MAC 文件被锁定
从windows拷贝到MAC的文件,有时候会被锁定.右键-简介-已锁定也是灰色的,无法取消: xattr -l 文件名 xattr -d com.apple.FinderInfo 文件名
- python安装模块的时候报错error: command 'gcc' failed with exit status 1
[情况] 在写Python代码的时候,需要用到psutil模块,需要安装. 但是在安装时,报错:error: command 'gcc' failed with exit status 1 [解决步骤 ...
- 构建基于TCP的应用层通信模型
各层的关系如下图,表述的是两个应用或CS间通信的过程: 通常使用TCP构建应用时,需要考虑传输层的通信协议,以便应用层能够正确识别消息请求.比如,一个请求的内容很长(如传文件),那肯定要分多次发送 ...
- Codeforces 799B - T-shirt buying(STL)
题目链接:http://codeforces.com/problemset/problem/799/B 题目大意:有n件T恤,每件T体恤都分别有价格(每件衣服的价格不重复).前面的颜色.背部的颜色三种 ...
- MySQL-高并发优化
一.数据库结构的设计 1.数据行的长度不要超过8020字节,如果超过这个长度的话在物理页中这条数据会占用两行从而造成存储碎片,降低查询效率. 2.能够用数字类型的字段尽量选择数字类型而不用字符串类型的 ...
- HDRtools-OpenExr
转:http://blog.csdn.net/lqhbupt/article/details/7917764 OpenEXR是由工业光魔(Industrial Light& Magic)开发的 ...
- AXFR和IXFR区域传输及原理
由于区域在DNS中发挥着重要的作用,因此希望在网络上的多个DNS服务器中提供区域,以提供解析名称查询时的可用性和容错.否则,如果使用单个服务器而该服务器没有响应,则该区域中的名称查询会失败.对于主要区 ...
- CTF中的EXP编写技巧 zio库的使用
zio库没有提供文档 这个是官方给出的一个例子程序 from zio import * io = zio('./buggy-server') # io = zio((pwn.server, 1337) ...