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;
    }
    
  • 相关阅读:
    BZOJ2061 : Country
    BZOJ3591: 最长上升子序列
    BZOJ4356 : Ceoi2014 Wall
    BZOJ2159 : Crash 的文明世界
    BZOJ2149 : 拆迁队
    BZOJ2739 : 最远点
    BZOJ4068 : [Ctsc2015]app
    BZOJ4361 : isn
    BZOJ4404 : [Neerc2015]Binary vs Decimal
    BZOJ4402 : Claris的剑
  • 原文地址:https://www.cnblogs.com/AWCXV/p/14068059.html
Copyright © 2011-2022 走看看