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;
    }
    
  • 相关阅读:
    xcode修改默认头部注释(__MyCompanyName__) (转)
    ios7注意事项随笔
    二分查找(BinarySearch)
    选择排序(SelectionSort)
    插入排序(InsertionSort)
    堆排序(HeapSort)
    归并排序(MergeSort)
    快速排序(QuickSort)
    基本-正则表达式
    2.5亿个整数中找出不重复的整数
  • 原文地址:https://www.cnblogs.com/pureayu/p/14826838.html
Copyright © 2011-2022 走看看