codeforces1400B (Educational Codeforces Round 94) RPG Protagonist

题目链接:

https://codeforces.com/contest/1400/problem/B
题目大意:


你与你的伙伴要拿两种武器,你能拿总共p重量的物体,你伙伴能拿共f重量的物体。
两种武器一种是剑,重量为s,数量为cnts
另一种是斧头,重量为e,数量为cnte,

现在问你和你的伙伴最多一共能拿多少件武器


输入与输出:
 

input

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

output

11
20
3


思路:

你与你的伙伴要拿两种武器,你能拿总共p重量的物体,你伙伴能拿共f重量的物体。
两种武器一种是剑,重量为s,数量为cnts
另一种是斧头,重量为e,数量为cnte

如果这题只有一人拿武器,那肯定就是直接贪心,先拿轻的,再拿重的
但是现在有两人,那么我们可以直接枚举第一个人拿剑的数量(s1),那么第一个人拿斧头的数量就确定了(w1)
那么就只剩下第二个人与剩下的武器了

那么每次的答案就是 s1 + w1 + s2 + w2
每次取个max即可


代码:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define int long long

int p, f;
int cntS, cntE;
int s, e;

signed main()
{
	int t;

	scanf("%lld", &t);
	while (t--) {
		scanf("%lld%lld%lld%lld%lld%lld", &p, &f, &cntS, &cntE, &s, &e);
		int s1, e1, s2, e2;
		int res = 0;

		if (s > e) {
			swap(s, e);
			swap(cntS, cntE);
		}

		for (s1 = 0; s1 <= cntS; s1++) {
			if (s1 * s > p) break;
			else {
				e1 = (p - (s1 * s)) / e;
				e1 = min(cntE, e1);
				
				s2 = f / s;
				s2 = min(cntS - s1, s2);
				e2 = (f - (s2 * s)) / e;
				e2 = min(cntE - e1, e2);
				res = max(res, s1 + s2 + e1 + e2);
			}
		}
		printf("%lld\n", res);
	}
	return 0;
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值