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 ...
随机推荐
- JavaScript 跳转 页面
* window.location.href , self.location, window.location 出现问题不能跳转 Chome 不能本页跳转, IE 有时可以
- ansible报错Aborting, target uses selinux but python bindings (libselinux-python) aren't installed
报错内容: TASK [activemq : jvm configuration] ********************************************************** ...
- RSA加密登录
1.首先下载前端JS加密框架:jsencrypt 2.后台添加解密帮助类:RSACrypto(参考文章最后) 3.在登录页面先引入jquery.min.js,在引入jsencrypt.min.js 4 ...
- java基础9 main函数、this、static、super、final、instanceof 关键字
一.main函数详解 1.public:公共的.权限是最大的,在任何情况都可以访问 原因:为了保证jvm在任何情况下都可以访问到main法2.static:静态,静态可以让jvm调用更方便,不需要用 ...
- 【前端笔记】浅谈js继承
我们先想想我们用js最后要怎样实现面向对象的编程.事实上我们必须用上原型链这种东西. 我们的父类superType有属性和方法,并且一些能被子类subType继承,一些能被覆盖,但是丝毫不会影响到父类 ...
- 洛谷P1789【Mc生存】插火把 题解
题目传送门 这道题目可以纯暴力: #include<bits/stdc++.h> //Minecraft 666 using namespace std; ][]; int n,m,k,a ...
- Centos bash: make: command not found
一般出现这个bash: make: command not found提示,是因为安装系统的时候使用的是最小化mini安装,系统没有安装make.vim等常用命令,直接yum安装下即可: yum -y ...
- 火狐 firefox proxy moz=proxy:// 407错误 解决办法
设置代理后,访问任一网站均弹窗要求输入代理的用户名和密码,但是多次输入始终无法认证. 最后才发现原来firefox把代理服务器的认证信息当成网站的认证信息记录了. 解决方法:将已登录信息中的代理相关的 ...
- lr_start_timer,lr_get_transaction_duration,lr_get_transaction_wasted_time函数使用总结
lr_start_timer: 函数的功能: 为了计算时间更加精确,可以用这个函数去掉LR自身的检查点所浪费的时间.如text check and image time Action() { doub ...
- 【C#】利用反射构建实体
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...