Codeforces 488 C. Fight the Monster(模拟)

本文详细介绍了如何通过暴力枚举法解决Codeforces平台上的C题'Fight the Monster'。该题涉及到角色属性的优化与战斗回合数的计算,通过枚举最终攻击力和防御力,来最小化所需消耗的金币。本文提供了完整的AC代码及解题思路,适合对Codeforces平台题解感兴趣的读者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Fight the Monster

题目链接:

http://codeforces.com/problemset/problem/488/C

解题思路:

Codeforces官方题解:

It is no use to make Yang's ATK > HP_M + DEF_M (Yang already can beat it in a second). And it's no use to make Yang's DEF > ATK_M (it cannot deal any damage to him).

As a result, Yang's final ATK will not exceed 200, and final DEF will not exceed 100. So just enumerate final ATK from ATK_Y to 200, final DEF from DEF_Y to 100.

With final ATK and DEF known, you can calculate how long the battle will last, then calculate HP loss. You can easily find the gold you spend, and then find the optimal answer.

因为题目数据量较小,所以直接枚举暴力即可求出答案.(All numbers in input are integer and lie between 1 and 100 inclusively.

AC代码:

#include <iostream>
#include <cstdio>
#define INF 0xfffffff
using namespace std;
int main(){
    int hy,ay,dy;
    int hm,am,dm;
    int h,a,d;
    while(scanf("%d%d%d",&hy,&ay,&dy)!=EOF){
        scanf("%d%d%d",&hm,&am,&dm);
        scanf("%d%d%d",&h,&a,&d);
        int i,j,k,ans=INF;
        for(i = 0; i <= 200; i++) //攻击
            for(j = 0; j <= 200; j++) //防御
                for(k = 0; k <= 1000; k++){//血量
                    if(ay+i <= dm)
                        continue;
                    int t = (hm-1)/(ay+i-dm)+1;//战斗的时间
                    if(k <= t*(am-dy-j)-hy)
                        continue;
                    ans = min(ans,h*k+a*i+d*j);
                }
        printf("%d\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值