zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Understanding identities in IIS
    Name your feature branches by convention
    Branch policies on Azure Repos
    Use Git Credential Managers to Authenticate to Azure Repos
    How do I force my .NET application to run as administrator?
    UML的类型
    ASP.NET Error Handling
    通过泛型,将string转换为指定类型
    Spring Session + Redis实现分布式Session共享
    MongoDB中的数据导出为excel CSV 文件
  • 原文地址:https://www.cnblogs.com/pureayu/p/14826838.html
Copyright © 2011-2022 走看看