B - RPG Protagonist

题目:http://codeforces.com/contest/1400/problem/B

提炼:两个人容量分别为p,f  装两种物品 体积分别为s,w  两物品数量分别为cnts,cntw;  给出以上数据,求两人最多装物品的数目

题解:贪心 先装体积小的物品     最终达到 p 装了 a个s,b个w;    f  装了 c个s,d个w;a+b+c+d为最大值

 

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<utility>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
ll p,f;
ll cnts,cntw;
ll s,w;
int main(){
	int T; cin>>T;
	while(T--){
		cin>>p>>f>>cnts>>cntw>>s>>w;
		if(s<w) swap(s,w), swap(cnts,cntw);  //把s做为体积大的那个
		ll maxs=p/s;
		ll res=0;
		for(ll i=0;i<=min(maxs,cnts);i++){   //从0枚举s
			ll a=i,b=min(cntw,(p-i*s)/w);
			ll d=min(f/w,cntw-b);
			ll c=min(cnts-i,(f-w*d)/s);
			res=max(res,a+b+c+d);
		}
		cout<<res<<endl;
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值