Codeforces_488C:Fight_the_Monster(暴力)
2017-01-15 21:49
288 查看
题意玩家和怪兽对决,玩家有hp1,att1,def1属性分别代表生命值、攻击力和防御值,怪兽也有对应的数值hp2,att2,def2.每次对决玩家会对怪兽造成max(0,att1-def2)的伤害,与此同时怪兽对玩家造成max(0,att2-def1)的伤害,当怪兽hp<=0而玩家hp>0时玩家获胜.玩家除了初始属性值外,还可以买买买来增强属性值,可以分别以h,a,d的代价分别增加自己一点生命值、攻击力或防御力,可以购买多次,问如果玩家想战胜怪兽至少需要花费多少代价.所有数值的范围在1~100之间.
看到数据范围,做法就十分明了了,直接暴力,可以暴力枚举买i次攻击力和j次防御力,这样就能算出玩家需要几轮攻击才能打败怪兽,以及这几轮下来需要承受的伤害值,这样便又能算出在如此购买攻击与防御力的情况下至少需要购买几次生命值,然后取所有代价的最小值作为最后答案即可,下附程序.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int maxx(int x,int y){if(x>y)y=x;return y;}
int minx(int x,int y){if(x<y)y=x;return y;}
int main()
{
int h1,h2,a1,a2,d1,d2,ph,pa,pd,i,j,k;
cin>>h1>>a1>>d1>>h2>>a2>>d2>>ph>>pa>>pd;
a1-=d2;a2-=d1;
k=99999999;
for(i=0;i<=200;i++)
for(j=0;j<=100;j++)if(a1+i>0)k=minx(k,pa*i+pd*j+ph*maxx(0,((h2-1)/(a1+i)+1)*maxx(0,a2-j)-h1+1));
cout<<k;
return 0;
}
看到数据范围,做法就十分明了了,直接暴力,可以暴力枚举买i次攻击力和j次防御力,这样就能算出玩家需要几轮攻击才能打败怪兽,以及这几轮下来需要承受的伤害值,这样便又能算出在如此购买攻击与防御力的情况下至少需要购买几次生命值,然后取所有代价的最小值作为最后答案即可,下附程序.
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
int maxx(int x,int y){if(x>y)y=x;return y;}
int minx(int x,int y){if(x<y)y=x;return y;}
int main()
{
int h1,h2,a1,a2,d1,d2,ph,pa,pd,i,j,k;
cin>>h1>>a1>>d1>>h2>>a2>>d2>>ph>>pa>>pd;
a1-=d2;a2-=d1;
k=99999999;
for(i=0;i<=200;i++)
for(j=0;j<=100;j++)if(a1+i>0)k=minx(k,pa*i+pd*j+ph*maxx(0,((h2-1)/(a1+i)+1)*maxx(0,a2-j)-h1+1));
cout<<k;
return 0;
}
相关文章推荐
- Codeforces 488C Fight the Monster【二分+枚举】
- codeforces 487 A Fight the Monster 暴力枚举
- Codeforces Round #278 (Div. 2) C. Fight the Monster(暴力)
- Codeforces Round #278 (Div. 1) A. Fight the Monster( 暴力)
- CodeForces 488 C.Fight the Monster(枚举)
- Codeforces 488 C. Fight the Monster && Codeforces Round #278
- Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力
- C - Fight the Monster(暴力)
- CodeForces 29D - Ant on the Tree 暴力LCA
- Codeforces #406 (Div. 2 A. The Monster&B. Not Afraid (暴力
- Codeforces 143A Help Vasilisa the Wise 2(暴力)
- Codeforces 842A. Kirill And The Game (暴力)
- Codeforces 3A. Shortest path of the king(贪心:暴力)
- hdu 2616 Kill the monster(stl全排列+暴力)
- [HDU] 2616 Kill the monster 一种基本剪枝的暴力深搜
- CodeForces 723C Polycarp at the Radio (题意题+暴力)
- Fight the Monster题解报告
- 【CodeForces】716B - Complete the Word(暴力)
- HDU 2616 Kill the monster (暴力搜索 || 终极暴力全排列)
- codeforces 3-A. Shortest path of the king(暴力)