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 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.

Sample test(s)
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.

打DIV1真是从头卡落未,差点爆0 , 最后还是过了 。

题意很容易懂。

然后我暴力枚举 3 个变量 初始值 ~ 200 。 过了小数据, 然后被hack 了 。

其实不然 , 因为monster 各个属性最大都是100。

那么Yang的攻击力最多枚举到201就可以秒了monster 。

防御力最多枚举到101就可保证自己滴血不伤 。

然而血量是可以好大的 。

我直接从初始值暴力找上去第一个合法的血量 。

这样都能过,可能数据是弱了。后来想过弄一个10的几次方二分快点。

其实也不用 。 你已经确定了2个值 ,直接通过公式就可以得出血量的下界了。

O(1)时间解决。

3层暴力代码:

#include <bits/stdc++.h>
using namespace std; typedef long long LL; const int N = ;
const int inf = 1e9 + ; int a ,b , c , hp1 , ac1 , of1, hp2 , ac2 , of2 ; bool check( int hp , int ac , int of ){
if( ac - of2 <= ) return false ; if( ac2 - of <= ) return true ;
if( ceil( (double) hp / ( ac2 - of ) ) > ceil( (double) hp2 / ( ac - of2 ) ) ) return true ;
return false ;
}
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
while( cin >> hp1 >> ac1 >> of1 >> hp2 >> ac2 >> of2 >> a >> b >> c ){
int ans = inf ;
if( of1 >= ac2 ) { if( ac1 > of2 ) cout << '' << endl ; else cout << ( of2 + - ac1 ) * b << endl; break ; }
for( int i = max( ac1 , of2 + ) ; i <= ; ++i ) {
for( int j = of1 ; j <= ac2 + ; ++j ){
for( int k = hp1 ; ; ++k ){
if( check( k , i , j ) ) {
ans = min( ans , ( k - hp1 ) * a + ( i - ac1 ) * b + ( j - of1 ) * c ) ; break ;
}
}
}
}
cout << ans << endl ;
}
return ;
}

Codeforces 488C Fight the Monster的更多相关文章

  1. codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)

    题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...

  2. Codeforces Round #278 (Div. 1) A. Fight the Monster 暴力

    A. Fight the Monster Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/487/ ...

  3. codeforces 487A A. Fight the Monster(二分)

    题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...

  4. Codeforces 954D Fight Against Traffic(BFS 最短路)

    题目链接:Fight Against Traffic 题意:有n个点个m条双向边,现在给出两个点S和T并要增加一条边,问增加一条边且S和T之间距离不变短的情况有几种? 题解:首先dfs求一下S到其他点 ...

  5. Codeforces - 102222H - Fight Against Monsters - 贪心

    https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1 ...

  6. Codeforces 918C/917A - The Monster

    传送门:http://codeforces.com/contest/918/problem/C 一个括弧串由字符‘(’和‘)’组成.一个正确的串可被递归地定义,定义如下: ①空串e是一个正确的串: ② ...

  7. 【codeforces 787A】The Monster

    [题目链接]:http://codeforces.com/contest/787/problem/A [题意] 把b一直加a->得到x 把d一直加c->得到y 然后问你x和y可不可能有相同 ...

  8. Codeforces 1296D - Fight with Monsters

    题目大意: n 只怪兽,每只的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b 打每只怪兽时,都是你先出手,然后你的对手出手,这样轮流攻击 如果是你给予了怪兽最后一击,你就能得到一分 你还 ...

  9. Codeforces Round #278 (Div. 2)

    题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...

随机推荐

  1. mybatis关联查询之一对多查询

    一对多,是最常见的一种设计.就是 A 表的一条记录,对应 B 表的多条记录,且 A 的主键作为 B 表的外键.这主要看以哪张表为中心,下面的测试数据中,从employee 表来看,一个员工对应一个部门 ...

  2. five hundred miles

  3. PdgCntEditor系列教程一:基础知识

    一.PdgCntEditor是什么? 二.为什么要用PdgCntEditor? 三.怎么用PdgCntEditor? 一.PdgCntEditor是什么? 这是一个目录编辑器,可以创建.编辑PDF.D ...

  4. jQuery对于demo元素的上移、下移、删除操作等实现

    今天给大家分享一个实用的jQuery技能:dom元素的操作:我们经常会去获取dom元素去实现交互效果,以及数据的操作. 首先复习一下jQuery DOM 元素方法: .get() 获得由选择器指定的D ...

  5. 好用的打包工具webpack

    <什么是webpack> webpack是一个模块打包器,任何静态资源(js.css.图片等)都可以视作模块,然后模块之间也可以相互依赖,通过webpack对模块进行处理后,可以打包成我们 ...

  6. struts2之ModelDriven

    在Struts 2中,提供了另外一种直接使用领域对象的方式,就是让action实现com.opensymphony. xwork2.ModelDriven接口.ModelDriven让你可以直接操作应 ...

  7. 想要成长,总得立个flag

    国庆假期结束了,自己的成长却丝毫没有,所以啊,立个flag试试看,每天能发表一个小知识点,希望自己能够做到,加油

  8. Linux历史命令管理以及用法

    history [-c] [-d offset] [n] history -anrw [filename] history -ps arg [arg...] -c: 清空命令历史 -d offset: ...

  9. 基于mybatis拦截器分表实现

    1.拦截器简介 MyBatis提供了一种插件(plugin)的功能,但其实这是拦截器功能.基于这个拦截器我们可以选择在这些被拦截的方法执行前后加上某些逻辑或者在执行这些被拦截的方法时执行自己的逻辑. ...

  10. java应用之solr入门篇

    前言 solr是apache项目的一款全文搜索应用. 官方文档http://lucene.apache.org/solr/guide/6_6/ 入门流程 1.安装   --->  2.启动  - ...