zoukankan      html  css  js  c++  java
  • 【例题 7-11 UVA

    【链接】 我是链接,点我呀:)
    【题意】

    在这里输入题意

    【题解】

    1.N/s1 < 1e6 枚举1的个数 2.N/s2<1e6 枚举2的个数

    3.s1和s2的值较小
    假设买了s2个1和s1个2
    那么这两种物品占的体积就一样大了。
    即都为s1s2
    而第一种物品价值为s2
    v1第二种物品价值为s1v2
    那么
    如果s2
    v1>s1v2的话。
    可以想见,如果第二种物品的数量超过了s1的话,显然可以把它占的体积都用来买物品1,因为那样更优。
    则我们第二种物品最多只要枚举到s1就可以了。
    同理s2
    v1<=s1*v2的话.
    第一种物品只要枚举到s2就可以了。

    【代码】

    /*
      	1.Shoud it use long long ?
      	2.Have you ever test several sample(at least therr) yourself?
      	3.Can you promise that the solution is right? At least,the main ideal
      	4.use the puts("") or putchar() or printf and such things?
      	5.init the used array or any value?
      	6.use error MAX_VALUE?
      	7.use scanf instead of cin/cout?
      	8.whatch out the detail input require
    */
    #include <bits/stdc++.h>
    #define ll long long
    using namespace std;
    
    ll n,s1,v1,s2,v2;
    
    int main(){
    	#ifdef LOCAL_DEFINE
    	    freopen("F:\c++source\rush_in.txt", "r", stdin);
    	#endif
    	ios::sync_with_stdio(0),cin.tie(0);
    	int T,kase = 0;
    	cin >> T;
    	while (T--){
    		cin >> n >> s1 >> v1 >> s2 >> v2;	
    		ll ans = 0;
    		if (n/s1<1e6){
    		 	for (int i = 0;i <= n/s1;i++){
    		 	 	ll temp = 1ll*i*v1;
    		 	 	ll tn = n - 1LL*s1*i;
    				temp += v2*(tn/s2);
    				ans = max(ans,temp);
    		 	}
    		}else if (n/s2<1e6){
    		 	for (int i = 0;i <= n/s2;i++){
    		 	 	ll temp = 1ll*i*v2;
    		 	 	ll tn = n - 1LL*s2*i;
    				temp += v1*(tn/s1);
    				ans = max(ans,temp);
    			}
    
     		}else {
    			if (s2*v1<s1*v2){ 			                            	
        		 	for (int i = 0;i <= s2;i++){
        		 	 	ll temp = 1ll*i*v1;
        		 	 	ll tn = n - 1LL*s1*i;
        				temp += v2*(tn/s2);
        				ans = max(ans,temp);
        		 	} 		 	
    		 	}else{
        		 	for (int i = 0;i <= s1;i++){
        		 	 	ll temp = 1ll*i*v2;
        		 	 	ll tn = n - 1LL*s2*i;
        				temp += v1*(tn/s1);
        				ans = max(ans,temp);
        		 	} 		 	
    		 	}
     		}
     		cout <<"Case #"<<++kase<<": "<<ans<<endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    【开源我写的富文本】打造全网最劲富文本系列之技术选型
    【开源我写的富文本】打造全网最劲富文本技术选型之经典OOP仍是魅力硬核。
    Jquery会死吗?我为什么不用vue写富文本!
    JavaScript的因为所以
    JavaScript寻踪OOP之路
    JavaScript谁动了你的代码
    JavaScript神一样的变量系统
    JavaScript的前世今生
    ASPICE对追踪性和一致性要求
    ASPICE:能力等级评定
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8036874.html
Copyright © 2011-2022 走看看