HDU 1171 Big Event in HDU
来源:互联网 发布:拍照软件哪个好 编辑:程序博客网 时间:2024/06/02 06:35
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10355 Accepted Submission(s): 3595
Problem Description
Nowadays, we all know that Computer College is 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 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).
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).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- 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 that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A is not less than B.
Sample Input
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
Author
lcy
#include <stdio.h>#include <stdlib.h>#include <string.h>int v[55], n[55];int f[250010];int main(){int N, V;int i, j, k;while(scanf("%d", &N), N >= 0){for (i = V = 0; i < N; i++){scanf("%d%d", &v[i], &n[i]);V += v[i] * n[i];}for (i = 0; i <= V / 2; i++) f[i] = -1;for (i = 0; i < N; i++){//printf("i = %d\n", i);if (v[i] > V / 2) continue;for (j = 0; j <= V / 2; j++){if (f[j] >= 0) f[j] = 0;else if (j >= v[i] && f[j - v[i]] >= 0 && f[j - v[i]] + 1 <= n[i])f[j] = f[j - v[i]] + 1;//printf("f[%d] = %d\n", j, f[j]);}}for (k = V / 2; k >= 0; k--)if (f[k] >= 0) break;printf("%d %d\n", V - k, k);}return 0;}/*TLE多次,结束标志是非负数,不一定是-1...WA了,跟上次同样的错,j从v[i]开始循环,没有更新v[i]以前的f[j]另外用单调队列优化的话,可以当做物品容量和价值相等的问题来做c[i] = v[i],多重背包一下,f[V/2]就是上述中最后的答案k*/
- 1171 Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- Big Event in HDU
- 03、pl/sql小结
- asp.net 2.0中的全球化与本地化
- linux daemon中执行system调用方法
- PHP 配置_(1):php.ini-recommended和php.ini-dist的区别
- SQLCODE and SQLSTATE Differences among IBM Relational Database Systems
- HDU 1171 Big Event in HDU
- xampp无法启动apache,提示terminating worker thread 0,问题原因与解决办法
- C++学习第7篇-数组和指针
- POJ 1742 Coins
- IM 开源项目 群组服务 数据库设计-数据库访问 (02)
- as和强制类型转换的区别
- 12-2-27关于笔试题常用链表的考察
- C++学习第8篇-函数深入
- Apache_通常每个套接字地址<协议>只允许使用一次_80端口问题