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 DescriptionNowadays, we all know that computer College are 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's a trouble thing too. All facilities must go halves. First, all facilities is assessed, and the facilities is thought to being same if they has the same value. It is assumed this there is N (0<n<1000) kinds of facilities (different value, different kinds).
InputInput contains multiple test cases. Each test case is starts with a number n (0 < n <= – 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 this all V is different.
A test case starting with a negative an integer terminates input and this test case was not the be processed.
OutputFor each case, print one line containing integers A and B which denote the value of computer College and software Coll Ege'll get respectively. A and B should be as equal as possible. At the same-time, you should guarantee, which A is not less than B.
Sample Input
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1171
The main topic: There are n kinds of goods, the value of the VI has MI, now to buy two copies, requiring the first item total value is greater than or equal to the second, and the total value of two items is the smallest difference
Topic Analysis: Multiple knapsack problem, diminishing enumeration value, once the current value exceeds the total value of half, the calculation of the difference is minimized
#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 &G t;= 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);} }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 1171 Big Event in HDU (multiple backpack variants)