B. RPG Protagonist Educational Codeforces Round 94 (Rated for Div. 2)

原题链接

B. RPG Protagonist

题目

在这里插入图片描述

输入

3
33 27
6 10
5 6
100 200
10 10
5 5
1 19
1 3
19 5

输出

11
20
3

Note

在这里插入图片描述

题意

你有一个容量为p的背包,你的随从有一个容量为f的背包,现在有cnts把重为s剑和cntw把重为w的斧,问你们最多能拿多少剑和斧。

思路

枚举可以装的剑和斧的最大数量,同时往自己和随从的背包里面装,最后取最大值。

代码:

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <list>
#include <set>
#include <cstdlib>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 55;
const int N = 10010;
const int INF = 0x3f3f3f3f;
const ll  LNF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 10007;
const double eps = 10e-6;
const double PI = 3.14159265358979323;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
priority_queue<int, vector<int>, less<int> >q;
priority_queue<int, vector<int>, greater<int> >qq;

int get(int cntss, int cntww, int ss, int ww, int ff){
	if (ss > ww) return get(cntww, cntss, ww, ss, ff);
	int buys = min (cntss, ff / ss);
	int sum = buys;
	ff -= buys * ss;
	sum += min(cntww, ff / ww);
	return sum;
}
int main(){
	int t;
	cin >> t;
	while (t--){
		int p, f, cnts, cntw, s, w;
		cin >> p >> f >> cnts >> cntw >> s >> w;
		int ans = 0, buy;
		for (int i = 0; i <= cnts; i++){
			if (i * s > p){
				break;
			}
			buy = min (cntw, (p - i * s) / w);
			ans = max (ans, i + buy + get (cnts - i, cntw - buy, s, w, f));
		}
		cout << ans << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值