zoukankan      html  css  js  c++  java
  • 【Codeforces Round #629 (Div. 3) D】Carousel

    题目链接

    链接

    翻译

    给你两种重量的物品, 重量分别为 (S)(W), 数量分别为 (cntS)(cntW)

    有两个人,第一个人的背包容量为 (p), 第二个人的背包容量为 (f)。要让这两个人拿走的物品的数量之和最大。

    问你最大可能为多少。

    即有数量限制,物品价值都相同为 (1) 要求最大数量。

    题解

    中间枚举的量记得要还原

    代码

    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #define LL long long
    using namespace std;
    
    int main() {
    	ios::sync_with_stdio(0), cin.tie(0);
    	int T;
    	cin >> T;
    	while (T--) {
    		int p, f,cnts,cntw,s,w;
    		cin >> p >> f;
    		cin >> cnts >> cntw;
    		cin >> s >> w;
    		if (s > w){
    		    swap(s,w);
    		    swap(cnts,cntw);
    		}
    		int ans = 0;
    		for (LL i = 0; i <= cnts; i++) {
    			LL weight = i*s;
    			if (p - weight >= 0) {
    				LL rest = p - weight;
    				LL j = rest / w;
    				j = min(j, 1LL*cntw);
    				int rests = cnts - i, restw = cntw - j;
    
    				int chooseSNumber = min(f / s, rests);
    				;
    				int chooseWNumber = min((f - chooseSNumber*s)/w,restw);
    				int tAns = i + j + chooseSNumber + chooseWNumber;
    				ans = max(ans, tAns);
    			}
    		}
    		cout << ans << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    elment ui 日期限制
    javascript中的编码与解码
    vue3 px 转ref
    css 波浪线
    初始化css
    vue 3 的复制功能 vue-clipboard3
    二维数组转一维数组、对象数组互斥去重
    分享几个数组方法
    前端生成图形验证码
    rem自适应布局,移动版
  • 原文地址:https://www.cnblogs.com/AWCXV/p/14068059.html
Copyright © 2011-2022 走看看