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;
    }
    
  • 相关阅读:
    CAN总线(1)--初探(更新中)
    无约束时钟导致综合实现效果不一致
    推荐几本FPGA书籍(更新中)
    Ubuntu下配置支持Windows访问的Samba共享
    svn 节点处冲突 解决
    clock()、time()、clock_gettime()和gettimeofday()函数的用法和区别
    Linux入门,这七大习惯得有!
    Ubuntu硬盘空间不足时,添加硬盘的方法
    让你快速学会Shell脚本
    printf与fprintf函数的区别
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8036874.html
Copyright © 2011-2022 走看看