Zombie's Treasure Chest UVA - 12325(贪心枚举)

题意

给你一个背包体积为n,现在有两种价值的物品,s1表示1号物品的体积,v1为价值s2,v2代表第二种物品。两种物品能够无限拿,问你最大的价值为多少

思路

看到这个很容易想到背包问题,但是longlong类型的数组存不下,所以我们考虑贪心策略。

s2件一号物品和s1件2号物品,两者的体积相同,在体积相同的情况下优先拿价值高的,所以我们进行比较sum1,sum2,如果sum1>=sum2那么就说明优先拿一号物品,我们还知道这种情况下2号物品最多只能拿s1-1件,因为如果二号物品拿s1件的话那么这时候显然拿一号物品的价值更大,因为sum1>=sum2。所以我们能够知道了二号物品的上界,然后枚举二号物品就行了。另外一种情况同理

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
ll n,s1,v1,s2,v2,ans;
int main()
{
    int T;scanf("%d",&T);
    for(int kace=1;kace<=T;kace++)
    {
        scanf("%lld%lld%lld%lld%lld",&n,&s1,&v1,&s2,&v2);
        ll sum1=v1*s2;
        ll sum2=v2*s1;
        ll ans=0;
        if(sum1>=sum2)
        {
            ll t=n/s2;
            t=min(t,s1-1);
            for(ll i=0;i<=t;i++)
            {
                ll ss1=i*v2;
                ll ss2=(n-i*s2)/s1*v1;
                ans=max(ans,ss1+ss2);
            }
        }
        else
        {
            ll t=n/s1;
            t=min(t,s2-1);
            for(ll i=0;i<=t;i++)
            {
                ll ss1=i*v1;
                ll ss2=(n-i*s1)/s2*v2;
                ans=max(ans,ss1+ss2);
            }
        }
        printf("Case #%d: %lld\n",kace,ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Zombie Raid is a thrilling top-down shooter survival game set in a post-apocalyptic world overrun by zombies. The game features fast-paced action, challenging gameplay, and a variety of weapons and power-ups to help you survive. As a survivor, your goal is to protect your base from the endless waves of zombies. You'll need to use your wits and quick reflexes to stay alive and fend off the undead hordes. The game features a variety of weapons, from pistols and shotguns to assault rifles and rocket launchers, to help you take down the zombies. In addition to weapons, you can also collect power-ups like health kits, ammo crates, and special abilities to help you survive. These power-ups can be found scattered throughout the game world, so be sure to explore and scavenge as much as possible. Zombie Raid also features a variety of enemies, from slow-moving zombies to fast and agile ones, as well as bosses that require strategy and skill to defeat. You'll need to adapt to each new wave of enemies and use different tactics to survive. The game also features multiple levels, each with its own unique challenges and objectives. As you progress through the game, you'll unlock new weapons and abilities, making it easier to take on the hordes of zombies. Overall, Zombie Raid is a fun and exciting top-down shooter survival game that will keep you on the edge of your seat. With its challenging gameplay, variety of weapons and power-ups, and endless waves of zombies, it's a game that's sure to keep you entertained for hours on end.

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值