Codeforces 488 C. Fight the Monster(模拟)

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


你可能感兴趣的:(模拟)