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

被折叠的 条评论
为什么被折叠?



