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;
    }
    
  • 相关阅读:
    html和css简介;
    包装函数,面向切面的函数实现;
    RegExp
    javascript基础语法&5
    用Pyinstaller把Python3.7程序打包成可执行文件exe
    Idea下安装Lombok插件
    Moco框架jar下载地址
    安装时后的idea,项目不能运行,pom.xml文件不能下载到本地仓库,maven配置是正确的
    如何使用Git命令将项目从github或者服务器上克隆下来
    github怎么创建一个项目,怎么添加一个ssh-key的客户
  • 原文地址:https://www.cnblogs.com/AWCXV/p/8036874.html
Copyright © 2011-2022 走看看