CodeForces 487 A.Fight the Monster(枚举)

Description
两个人对打,每个人有一个血量hi,攻击力ai和防御力di,每次可以给对方造成max(0,ai-dj)的伤害,第一个人可以从商店买东西加血加攻击加防御,每增加一点这三种值分别花费h,a,d,问打败对方的最小花费
Input
九个介于1到100的整数h1,a1,d1,h2,a2,d2,h,a,d分别表示两个人的血量攻击力防御力以及增幅药品的花费
Output
输出打败对方的最小花费
Sample Input
1 2 1
1 100 1
1 100 100
Sample Output
99
Solution
由于所有值都不大于100,故直接枚举增加的攻击力和防御力然后求出打败对方需要加的血量来更新最小花费即可
Code

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
#define maxn 1111
int h1,a1,d1,h2,a2,d2,h,a,d;
int main()
{
    while(~scanf("%d%d%d%d%d%d%d%d%d",&h1,&a1,&d1,&h2,&a2,&d2,&h,&a,&d))
    {
        int ans=INF;
        for(int i=0;i<=200;i++)
            for(int j=0;j<=200;j++)
            {
                if(a1+i<=d2)continue;
                int t=h2/(a1+i-d2)+(h2%(a1+i-d2)==0?0:1);
                int hurt=t*max(0,a2-d1-j);
                if(h1>hurt)ans=min(ans,a*i+d*j);
                else ans=min(ans,h*(hurt+1-h1)+a*i+d*j);
            } 
        printf("%d\n",ans);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值