首页 > 其他分享 >HDU 1171 Big Event In HDU

HDU 1171 Big Event In HDU

时间:2022-10-25 17:04:22浏览次数:64  
标签:HDU int Big Computer College test include Event


题目链接:​​传送门​


Big Event in HDU

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).

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.

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

2
10 1
20 1
3
10 1
20 2
30 1
-1

Sample Output

20 10
40 40

题目大意:

HDU要分家了,分成两个技术院,现在有台设备,每台设备都有一定的价值和数量,现在要使两个技术院设备的总价值尽量相同

把背包容量设成这些设备数量和价值的乘积
要尽量填起这半个背包
然后做多重背包就好了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <vector>
#include <iomanip>
#define
#define
#define

using namespace std;
int n, V, w[A], c[A], f[A];

int main() {
while (cin >> n) {
if (n < 0) return 0;
memset(f, 0, sizeof f); V = 0;
for (int i = 1; i <= n; i++) {
cin >> w[i] >> c[i];
V += w[i] * c[i];
}
for (int i = 1; i <= n; i++)
for (int k = 0; k < c[i]; k++)
for (int j = V / 2; j >=w[i]; j--)
f[j] = max(f[j], f[j - w[i]] + w[i]);
cout << max(f[V / 2], V - f[V / 2]) << " " << min(f[V / 2], V - f[V / 2]) << endl;
}
}


标签:HDU,int,Big,Computer,College,test,include,Event
From: https://blog.51cto.com/lyle/5794950

相关文章

  • HDU 3535 AreYouBusy
    题目链接:​​传送门​​题面:AreYouBusyProblemDescriptionHappyNewTerm!Ashavingbecomeajunior,xiaoArecognizesthatthereisnotmuchtimeforhertoAC......
  • HDU 2844 Coins
    题目链接:​​传送门​​​题面:ProblemDescriptionWhuacmersusecoins.TheyhavecoinsofvalueA1,A2,A3…AnSilverlanddollar.OnedayHibixopenedpurseandfoun......
  • HDU 1203 I NEED A OFFER!
    题目链接:​​传送门​​题面:INEEDAOFFER!ProblemDescriptionSpeakless很早就想出国,现在他已经考完了所有需要的考试,准备了所有要准备的材料,于是,便需要去申请学校了......
  • HDU 1114 Piggy-Bank
    题目链接:​​传送门​​Piggy-BankProblemDescriptionBeforeACMcandoanything,abudgetmustbepreparedandthenecessaryfinancialsupportobtained.Them......
  • HDU 2546 饭卡
    题目链接:​​传送门​​题面:ProblemDescription电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前判断余额。如果购买一个商品之前,卡上的剩余金额大于或等于5元,就一......
  • HDU 2602 Bone Collector
    题目链接:​​传送门​​​题面:ProblemDescriptionManyyearsago,inTeddy’shometowntherewasamanwhowascalled“BoneCollector”.Thismanliketocollec......
  • macOS Big Sur 11.7.1 (20G918) 正式版 ISO、PKG、DMG、IPSW 下载
    本站提供的macOSBigSur软件包,既可以拖拽到Applications(应用程序)下直接安装,也可以制作启动U盘安装,或者在虚拟机中启动安装。请访问原文链接:https://sysin.cn/blog/m......
  • macOS Big Sur 11.7 (20G817) Boot ISO 原版可引导镜像
    本站下载的macOSBigSur软件包,既可以拖拽到Applications(应用程序)下直接安装,也可以制作启动U盘安装,或者在虚拟机中启动安装。请访问原文链接:https://sysin.org/blog......
  • kafka与eventing
    项目地址https://strimzi.io/quickstarts/https://github.com/strimzi/strimzi-kafka-operator/tree/0.31.1/examples/kafka部署ClusterRole和CRDkubectlcreate-f'h......
  • HDU2376 Average distance
    题目链接:传送门求树上任意两点间的路径和的平均值非常套路统计每条边被经过多少次就是两边的点数的乘积注意精度就好#include<cstdio>#include<cstring>#include<alg......