• RPG Protagonist


    RPG Protagonist

    这个题目只需要遍历一下就行了,从轻的那一个从最大往小循环,找最值,只有这样才能保证最优。

    #include <bits/stdc++.h>
    using namespace std;
    
    
    typedef long long ll;
    void solve(){
    	ll p, f, cnts, cntw, sw, ww;
    	cin >> p >> f >> cnts >> cntw >> sw >> ww;
    	if(sw > ww){
    		swap(sw, ww);
    		swap(cnts, cntw);
    	}
    	ll ans = 0;
    	for(int i = cnts; i >= 0; i --){	//从0个剑开始选直到选到cnts个,找最大值 
    		int num = i;	//num为刀的数量 
    		ll tempcnts = cnts, tempcntw = cntw;
    		ll tempmax = 0, meca = p, foca = f;
    		if(meca >= num * sw){
    			tempmax += num;
    			meca -= num * sw;
    			num = 0;
    		}else if(meca >= sw){
    			tempmax += meca / sw;
    			num -= meca / sw;
    			meca -= meca / sw * sw;
    		}
    		//全部取完或者取完一部分
    		//1.如果取完,则判断剩余容量是否能放wax,并且还要判断sword是否已经被取完,没取完继续取,取完再判断是否能取wax 
    		//2.如果只取一部分,则判断剩余容量是否能放wax;
    		
    		int ts = cnts - i + num; //sword的剩余数量 
    		if(foca >= sw){
    			int tt = foca / sw;
    			if(tt >= ts){
    				tempmax += ts;
    				foca -= ts * sw;
    				ts = 0;
    			}else{
    				tempmax += foca / sw;
    				ts -= tt;
    				foca -= tt * sw;
    			}
    		}
    		if(meca >= ww){
    			int tw = meca / ww;
    			if(tw >= tempcntw){
    				tempmax += tempcntw;
    				meca -= tempcntw * ww;
    				tempcntw = 0;
    			}else{
    				tempmax += meca / ww;
    				tempcntw -= meca / ww;
    				meca -= meca / ww * ww;
    			}
    		}
    		//if(i == 7)
    		//	cout << "foca = " << foca << " tempcntw = " << tempcntw << endl;
    		if(foca >= ww){
    			int tw = foca / ww;
    			if(tw >= tempcntw){
    				tempmax += tempcntw;
    				tempcntw = 0;
    			}else{
    				tempmax += tw;
    				tempcntw -= tw;
    			}
    		}
    		//if(i == 7)
    		//	cout << "i = " << i << " foca = " << foca << " tempmax = " << tempmax << endl;
    		ans = max(ans, tempmax);
    	} 
    	cout << ans << endl;
    			
    }
    int main(){
    	int t;
    	cin >> t;
    	while(t --){
    		solve();
    	}
    	 
    	
    	return 0;
    }
    
  • 相关阅读:
    inner join和join
    Java输入输出流
    数据库基础——并发控制
    逻辑题
    数据库基础——数据库设计
    JDBC
    XmlHttpRequest
    servlet乱码
    Tomcat缺少服务
    poj2388---求奇数个数字的最中间的数
  • 原文地址:https://www.cnblogs.com/pureayu/p/14826838.html
Copyright © 2020-2023  润新知