codeforces 487 A Fight the Monster 暴力枚举
来源:互联网 发布:男士补水面膜 知乎 编辑:程序博客网 时间:2024/05/20 19:28
链接:http://codeforces.com/problemset/problem/487/A
题意:
给定自己以及怪物的血量,攻击,防御,定义每次攻击扣的血都是对方的攻击-自己防御,当然如果防御比对方的攻击高则不扣血。有三种药品,分别是加血,加攻,加防。给定每种药品的价格。判定如何花最少的钱打败怪兽,定义打败为自己的血量>0 ,并且怪兽的血量<= 0。
思路:
暴力枚举,因为可以知道防御力最多加到100就够了,而攻击力最多加到200,但是没有办法判断血量的上限是多少,所以这样不能够直接枚举这三种属性。一开始写的时候就是枚举了三种属性,其实血量的上限不是在200的,这是不能确定的。所以应该想到挑战上提到过的一种方法,枚举其中两个,计算出所需要的另外一种。
于是这道题,可以枚举攻击力和防御力,从而计算出所需要的最少的血量,并算出此时所需要的钱,更新答案。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define M 109#define INF 0x3f3f3f3fint hp1,atk1,def1;int hp2,atk2,def2;int main(){ while(scanf("%d %d %d",&hp1,&atk1,&def1) == 3) { scanf("%d %d %d",&hp2,&atk2,&def2); int a,b,c; scanf("%d %d %d",&a,&b,&c); int cost = INF; for(int i = max(atk1,def2+1);i <= 200;i++) { for(int j = def1;j <= 100;j++) { int time; if(hp2 %(i-def2) == 0) time = hp2 /(i-def2); else time = hp2 / (i-def2) + 1; int p = time*(atk2-j)+1; //打败monster所需的hp if(p >= hp1) p = p - hp1; //需要补充的hp else p = 0; cost = min(cost,p*a+b*(i-atk1)+c*(j-def1)); } } printf("%d\n",cost); } return 0;}
0 0
- codeforces 487 A Fight the Monster 暴力枚举
- Codeforces 487A Fight the Monster(暴力)
- codeforces #487A# Fight the Monster(枚举)
- codeforces 487A Fight the Monster
- 【Codeforces】 487A Fight the Monster
- CodeForces 487A Fight the Monster
- Codeforces 487A Fight the Monster
- Codeforces Round #278 (Div. 1) A. Fight the Monster( 暴力)
- Codeforces Round #278 (Div. 2) C. Fight the Monster(暴力)
- codeforces 488C Fight the Monster(枚举)
- Codeforces 488C Fight the Monster【二分+枚举】
- CodeForces 488 C.Fight the Monster(枚举)
- Codeforces Round #278 (Div. 2) C. Fight the Monster 二分+枚举
- CF488C Fight the Monster
- Codeforces Round #278 (Div. 2) 488C.Fight the Monster
- Codeforces 488 C. Fight the Monster(模拟)
- CodeForces 787A The Monster
- CF_487A Fight the Monster(二分)
- 信号处理一些知识
- 【2015年总】——留不住的青春,散不去的梦
- Linux学习--Linux系统日常管理1
- ZOJ 2965 Accurately Say "CocaCola"!
- iOS开发UI -- UIAlertController(提示框)
- codeforces 487 A Fight the Monster 暴力枚举
- STL中的模板介绍
- 摄像机模型与标定—棋盘、亚像素角点和绘制棋盘角点
- mysql重做日志
- 引用别人的项目cannot change version
- 敏捷测试的方法和实践
- Two-Stream Convolutional Networks for Action Recognition in Video
- PHP 实现定时任务的几种方法
- DVB-AD 注册