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 ...
随机推荐
- [转载]Selenium実行中にJavaScriptのコードを実行する
Selenium実行中にJavaScriptのコードを実行する JavaScriptで画面の値を取得/設定するコードをメモ. WebDriverEx.cs // JavaScriptを実行(戻り値なし ...
- java在图片上写字
- bug优先级定义
优先级定义如下: <版本前期阶段>(功能刚提测): [P0—紧急]:完全不能满足产品要求,基本功能明显未实现或完全不可用,阻塞测试流程与进度(核心功能流程) 1.功能未实现 .功能缺失 2 ...
- jquery 获取某a标签的href地址 实现页面加载时跳转
jQuery(document).ready(function(){if(jQuery("#zzjg a").length>0){var hrefValue = jQuery ...
- webpack3.0+总结
ul>li{ color:blue; font-size:20px } .items>ul>li>ul>li{ color:crimson } --> webpac ...
- AngularJS Intellisense in Visual Studio 2012
Recently, a lot of people have asked for Intellisense support for AngularJS in the Visual Studio HTM ...
- 454. 四数相加 II
给定四个包含整数的数组列表 A , B , C , D ,计算有多少个元组 (i, j, k, l) ,使得 A[i] + B[j] + C[k] + D[l] = 0. 为了使问题简单化,所有的 A ...
- spring源码分析 contextConfigLocation属性的位置
<context-param> <param-name>contextConfigLocation</param-name> <param-value> ...
- Bakery CodeForces - 707B (最短路的思路题)
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. The ...
- onvif 开发中的一些重要函数介绍
➤soap结构中count(soap->count)成员 soap结构中count(soap->count)成员记录的是http协议中Content-Length的数值. ➤keep_al ...