【例题 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;
}

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

时间: 2024-07-30 18:10:07

【例题 7-11 UVA - 12325】Zombie's Treasure Chest的相关文章

UVa 12325 Zombie&#39;s Treasure Chest【暴力】

题意:和上次的cf的ZeptoLab的C一样,是紫书的例题7-11 不过在uva上交的时候,用%I64d交的话是wa,直接cout就好了 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include&l

UVa 12325 - Zombie&#39;s Treasure Chest-[分类枚举]

12325 Zombie’s Treasure Chest Some brave warriors come to a lost village. They are very lucky and find a lot of treasures and a big treasure chest, but with angry zombies. The warriors are so brave that they decide to defeat the zombies and then brin

12325 - Zombie&#39;s Treasure Chest.

简单枚举+巧妙躲避大枚举量 #include<bits/stdc++.h> using namespace std; long long n,s1,v1,s2,v2,total; int main() { ios::sync_with_stdio(false); long long T,maxn=0; cin>>T; while(T--) { cin>>n>>s1>>v1>>s2>>v2; total=0; long lo

UVA 12325 Zombie&#39;sTreasureChest

看上去非常像背包的问题,但是体积太大了. 线性规划的知识,枚举附近点就行了,优先选性价比高的, 宝物有两种体积为S0,价值V0,体积S1,价值V1. 枚举分以下几种: 1:枚举拿宝物1的数量,然后尽量多拿宝物2:O(N/S0) 2:枚举拿宝物2的数量,同上:O(N/S1) 3.贪心,尽量选性价比高的 令gcd(S0,S1)= t,S1/t*S0 = S0/t*S1:体积相同的情况下尽量选价值高的,如果S1*V0>S0*V1大,那么枚举拿宝物2的数量,最多S0/t-1个否则一定可以换成S1/t个宝

一道看似dp实则暴力的题 Zombie&#39;s Treasure Chest

 Zombie's Treasure Chest 本题题意:有一个给定容量的大箱子,此箱子只能装蓝宝石和绿宝石,假设蓝绿宝石的数量无限,给定蓝绿宝石的大小和价值,要求是获得最大的价值 题解:本题看似是dp中的背包问题,但是由于数据量太大,用dp肯定会超时,所以只能寻找另外一种思路,可以用贪心加暴力,先求出两种宝石大小的最小公倍数com,然后将N/com-com,与N%comkanchengs看成是两个部分(想想应该明白).将前一个部分,放入单位价值量最高的那个,对于后面那个部分直接将S1的数量从

hdu4091 Zombie’s Treasure Chest

Zombie’s Treasure Chest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4442    Accepted Submission(s): 889 Problem Description Some brave warriors come to a lost village. They are very lucky an

UVa12325, Zombie&#39;s Treasure Chest

反正书上讲的把我搞得晕头转向的,本来就困,越敲越晕...... 转网上一个大神写的吧,他分析的很好(个人感觉比书上的清楚多了) 转:http://blog.csdn.net/u010536683/article/details/12450865 UVa12325, Zombie's Treasure Chest

hdu 4091 Zombie’s Treasure Chest 贪心+枚举

转自:http://blog.csdn.net/a601025382s/article/details/12308193 题意: 输入背包体积n,绿宝石体积s1,价值v1,蓝宝石体积s2,价值v2,宝石数目无限,问背包里能放下的最大价值? 题解: 看过去很像完全背包,可数据很大(虽然没给出,也能猜到,不然太水了),所以不能用背包求.又只有两种物品,想到了贪心,将价值与体积比大(称为价值比)的优先放入.但体积限制,这样还不可以,还需要枚举减少价值比大的宝石个数,是否可以增大所求价值.又我们可以知道

UVa 587 - There&#39;s treasure everywhere!

题目:你开始在坐标原点,想去目的地,给你一系列的指路信息,问目的地的位置和到原点的距离. 分析:模拟,计算几何.直接按照顺序计算即可,利用相对坐标求绝对坐标. 说明:注意输入格式. #include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include <cstdio> #include <cmath> using namespac