【例题 7-11 UVA - 12325】Zombie's Treasure Chest

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


在这里输入题意

【题解】


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;
}

转载于:https://www.cnblogs.com/AWCXV/p/8036874.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值