Fight the Monster

CodeForces - 487A

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 by max(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 1 HP, 1 ATK and 1 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.

Examples

Input
1 2 1
1 100 1
1 100 100
Output
99
Input
100 100 100
1 1 1
1 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.

sol:一开始想了好几个SB贪心都被自己否定掉了,猛然发现数据范围小的不像话,暴力枚举n2即可

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int inf=0x3f3f3f3f;
struct Record
{
int Hp,Atk,Def;
}a,b,Buy;
int main()
{
int i,j,k,ans=inf;
R(a.Hp); R(a.Atk); R(a.Def);
R(b.Hp); R(b.Atk); R(b.Def);
R(Buy.Hp); R(Buy.Atk); R(Buy.Def);
for(i=;i<=b.Hp;i++)//几回合干掉怪兽
{
int ATK=(b.Hp/i+(bool)(b.Hp%i))+b.Def;
for(j=;j<=b.Atk;j++)//增加几点防御
{
int DEF=a.Def+j;
int Sum=max(ATK-a.Atk,)*Buy.Atk+j*Buy.Def;
int Hp=max(b.Atk-DEF,)*i+;
ans=min(ans,Sum+max(Hp-a.Hp,)*Buy.Hp);
}
}
Wl(ans);
return ;
}
/*
Input
1 2 1
1 100 1
1 100 100
Output
99 Input
100 100 100
1 1 1
1 1 1
Output
0
*/

codeforces487A的更多相关文章

随机推荐

  1. LeetCode 178. 分数排名

    1.题目描述 编写一个 SQL 查询来实现分数排名.如果两个分数相同,则两个分数排名(Rank)相同.请注意,平分后的下一个名次应该是下一个连续的整数值.换句话说,名次之间不应该有“间隔”. +--- ...

  2. 阿里巴巴TXD前端小报 - 2019年3月刊

    原文:前端小报 - 201903月刊 Fundebug经授权转载,版权归原作者所有. [Alibaba-TXD 前端小报]- 热门前端技术快报,聚焦业界新视界:不知不觉 2019 年已经过去了 1/4 ...

  3. 手机端两端对齐,兼容ios,安卓

    .div-title p label{ text-align: justify; width: 18%; display: inline-block; text-align-last: justify ...

  4. 键盘上的"整蛊专家",如何防止短信轰炸机

    "短信轰炸机",是别人通过爬虫或者其他抓取手段在网路上收集那些公司平台短信业务接口的一个集成程序,可能只需要输入一个手机号,对方一整天都会收到各大平台的注册或提醒短信,就是手机在那 ...

  5. 总结:web 发展的4个阶段

    一.概述 随着人们的需求发展,web技术的发展也经历了多个阶段,下一个阶段总是伴随着解决上一阶段的问题,从静态文本.动态执行.动态自动生成文本,web应用,到web2.0,本文就详细描述这些阶段的特征 ...

  6. iOS ----------NSDate 、CFAbsoluteTimeGetCurrent、CACurrentMediaTime 的区别

    框架层: NSDate 属于Foundation CFAbsoluteTimeGetCurrent() 属于 CoreFoundatio CACurrentMediaTime() 属于 QuartzC ...

  7. TortoiseSVN 安装时出现 please install the universal crt

    解决步骤: 1.打开 https://www.microsoft.com/zh-cn/ 2.搜索 universal crt (hotfix kb2999226) 3.点击链接 4.选择适合自己的版本 ...

  8. 初级c++编码规范

        想了很久,第一篇文章还是应该写编码规范好一点.编码规范是一个仁者见仁的问题,为了避免复杂庞大,自己总结了一套简单版本的规范. 简介     本文介绍一份自己使用的C++编码规范.第一次正式进入 ...

  9. 某jiub笔试

    一.选择题 1.下列说法正确的有()A. class中的constructor不可省略B. constructor必须与class同名,但方法不能与class同名C.constructor在一个对象被 ...

  10. #019 还未搞明白的C语言问题

    吐槽一下作业系统 自己电脑上跑的好好地到他这里就给我算错了.... 是我的问题还是系统的问题?????摸不着头脑 总分 12 从键盘任意输入某班30个学生的成绩(成绩类型为整型),保存到数组中,并输出 ...