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;
    }
    
  • 相关阅读:
    绝对路径相对路径
    LN项目重构之职责链模式
    年度回忆录(2011.072011.12)
    协议学习建议
    UBUNTU下制作软盘映
    从汇编看c语言函数调用
    计算机底层入门知识杂记(一)——计算机启动流程解析
    自己动手写操作体统 pmtest1.asm 详细解释
    汇编函数与C函数的相互调用
    嵌入式linux驱动开发班
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8036874.html
Copyright © 2011-2022 走看看