codeforces #487A# Fight the Monster(枚举)

来源:互联网 发布:onlyanna淘宝 编辑:程序博客网 时间:2024/05/20 19:16

A. Fight the Monster
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A monster is attacking the Cyberland!

Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).

During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases bymax(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.

Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HPa bitcoins per ATK, and d bitcoins per DEF.

Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

Input

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HPATK and DEF of Master Yang.

The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HPATK and DEF of the monster.

The third line contains three integers h, a, d, separated by a space, denoting the price of HPATK and DEF.

All numbers in input are integer and lie between 1 and 100 inclusively.

Output

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

Sample test(s)
input
1 2 11 100 11 100 100
output
99
input
100 100 1001 1 11 1 1
output
0
Note

For the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.

For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.


解题思路:Master Yang打怪兽。双方都有三个属性(血,攻击力,防御力),同时放招,各自受到的伤害为 对方攻击力-自己的防御力。Master Yang可以去商店里买道具来加自己的三个属性。价格给定,问怎怎样可以花最少的钱来获得胜利。(自己的HP>0,怪兽的HP用完)

这道题的数据量比较小,直接用for循环嵌套枚举就可以了。但是需要注意的是Master Yang的攻击力最大只要加到200(自己攻击力为1,对方防御力100,血100.),防御力最大只要加到100就够了(加到100怪兽就打不死你了), 至于血可以根据前两个属性计算出最少需要加多少的血。然后全比较一遍就可以了。


/********************************//*Problem:  codeforces #478A#   *//*User:     shinelin        *//*Memory:     0 KB            *//*Time:     31 ms           *//*Language: GNU C++         *//********************************/#include <cstdio>#include <iostream>#include <cstdlib>#include <ctime>#include <cctype>#include <cstring>#include <string>#include <list>#include <map>#include <queue>#include <deque>#include <stack>#include <vector>#include <set>#include <algorithm>#include <cmath>using namespace std;#define INF 0x7fffffff#define LL long longint main(){    int HPy, ATKy, DEFy;    int HPm, ATKm, DEFm;    int hS, aS, dS;    scanf("%d%d%d", &HPy, &ATKy, &DEFy);    scanf("%d%d%d", &HPm, &ATKm, &DEFm);    scanf("%d%d%d", &hS, &aS, &dS);    int MinPrice = INF;    int h, time;    for (int a = 0; a <= 200; a ++)    {        for (int d = 0; d <= 100; d ++)        {            int hitY = max(0, ATKm - DEFy - d);            int hitM = max(0, ATKy + a - DEFm);            if(hitM == 0)   //打不死怪兽的情况                continue;            time = ceil(HPm * 1.0 / hitM);            if(time == 0) time = 1;            h = max(0, time * hitY - HPy + 1);            if(a * aS + d * dS + h * hS < MinPrice)            {                MinPrice = a * aS + d * dS + h * hS;            }        }    }    printf("%d\n", MinPrice);    return 0;}


0 0
原创粉丝点击