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 ...
随机推荐
- 【BubbleCup X】G:Bathroom terminal
一个hash的题 对?出现位置直接暴力枚举,然后hash判断下,扔进map里 cf的评测机跑的针tm块 #include<bits/stdc++.h> ; ; typedef long l ...
- javaScript-继承2种方式
1.组合继承 组合继承带来的问题很明细就是父类的构造函数会调用两次,如: function Person(name, age, sex) { this.name = name; this.age = ...
- GitHub vs GitLab:它们有什么区别?
查看原文GitLab vs. GitHub: How Are They Different? 两者都是基于web的Git repositories(仓库),拥有流水线型的web开发流程,它们为开发团队 ...
- linux 下配置文件目录/etc/sysconfig
/etc/sysconfig/目录详解 2010-06-19 11:12 6693人阅读 评论(1) 收藏 举报 桌面环境debugging防火墙serviceunix语言 /etc/sysconfi ...
- python之pandas&&DataFrame
1.Series Series是一个一维数组 pandas会默认从0开始作为Series的index >>> test = pd.Series(['num0','num1','nu ...
- hive学习(四) hive的函数
1.内置运算符 1.1关系运算符 运算符 类型 说明 A = B 所有原始类型 如果A与B相等,返回TRUE,否则返回FALSE A == B 无 失败,因为无效的语法. SQL使用”=”,不使用”= ...
- 编译报错:LC.exe 已退出
- 【58沈剑架构系列】主从DB与cache一致性
本文主要讨论这么几个问题: (1)数据库主从延时为何会导致缓存数据不一致 (2)优化思路与方案 一.需求缘起 上一篇<缓存架构设计细节二三事>中有一个小优化点,在只有主库时,通过“串行化” ...
- [原创] 基于RDP的桌面广播
之前写过一篇使用C# UDP 组播技术做的桌面广播实现, C# 使用UDP组播实现局域网桌面共享.最终效果差强人意,UDP包在不同的交换机上发送还会出现发送失败的情况,所以又重新研究了一些新的方法,包 ...
- js正则获取url参数,包含hash[#]和search[?]两种通用
function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&] ...