Codeforces 488C Fight the Monster
1 second
256 megabytes
standard input
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 HP, a 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.
The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang.
The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK 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.
The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.
1 2 1
1 100 1
1 100 100
99
100 100 100
1 1 1
1 1 1
0
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的更多相关文章
- codeforces 487a//Fight the Monster// Codeforces Round #278(Div. 1)
题意:打怪兽.可增加自己的属性,怎样在能打倒怪兽的情况下花费最少? 这题关键要找好二分的量.一开始我觉得,只要攻击到101,防御到100,就能必胜,于是我对自己的三个属性的和二分(0到201),内部三 ...
- 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/ ...
- codeforces 487A A. Fight the Monster(二分)
题目链接: A. Fight the Monster time limit per test 1 second memory limit per test 256 megabytes input st ...
- Codeforces 954D Fight Against Traffic(BFS 最短路)
题目链接:Fight Against Traffic 题意:有n个点个m条双向边,现在给出两个点S和T并要增加一条边,问增加一条边且S和T之间距离不变短的情况有几种? 题解:首先dfs求一下S到其他点 ...
- Codeforces - 102222H - Fight Against Monsters - 贪心
https://codeforc.es/gym/102222/problem/H 题意:有一堆怪兽,怪兽有HP和ATK.你有一个英雄,英雄每次先被所有怪兽打,然后打其中一个怪兽.打的伤害递增,第一次1 ...
- Codeforces 918C/917A - The Monster
传送门:http://codeforces.com/contest/918/problem/C 一个括弧串由字符‘(’和‘)’组成.一个正确的串可被递归地定义,定义如下: ①空串e是一个正确的串: ② ...
- 【codeforces 787A】The Monster
[题目链接]:http://codeforces.com/contest/787/problem/A [题意] 把b一直加a->得到x 把d一直加c->得到y 然后问你x和y可不可能有相同 ...
- Codeforces 1296D - Fight with Monsters
题目大意: n 只怪兽,每只的血量为 h[i] ,你的攻击力为 a ,你的对手攻击力为 b 打每只怪兽时,都是你先出手,然后你的对手出手,这样轮流攻击 如果是你给予了怪兽最后一击,你就能得到一分 你还 ...
- Codeforces Round #278 (Div. 2)
题目链接:http://codeforces.com/contest/488 A. Giga Tower Giga Tower is the tallest and deepest building ...
随机推荐
- 这么简单的 Redis 面试题都不懂,怎么拿offer?
来源:mp.weixin.qq.com/s/daBkliC8dAT_zYyoLiS7WA 随着系统访问量的提高,复杂度的提升,响应性能成为一个重点的关注点.而缓存的使用成为一个重点.redis 作为缓 ...
- Python3调用hessian
领导派了个任务,实现服务器日志文件调用hessian接口保存到数据库 研究了半天python调用hessian的办法 首先使用hessian for python的链接: http://hessian ...
- DNS解析全过程详解
1.Chrome浏览器 会首先搜索浏览器自身的DNS缓存(缓存时间比较短,大概只有1分钟,且只能容纳1000条缓存),看自身的缓存中是否有www.linux178.com 对应的条目,而且没有过期,如 ...
- Python的基本数据类型,用户交互
整数: int 常见的数字都是int类型. 用于计算或者大小的比较 在32位机器上int的范围是: -2**31-2**31-1,即-2147483648-2147483647 在64位机器上int的 ...
- PyQt5实战1-搭建conda环境
一.安装Anaconda 下载地址:https://repo.anaconda.com/archive/Anaconda3-2019.03-Windows-x86_64.exe 软件版本:Anacon ...
- java并发编程之美-阅读记录7
java并发包中的并发队列 7.1ConcurrentLinkedQueue 线程安全的无界非阻塞队列(非阻塞队列使用CAS非阻塞算法实现),其底层数组使用单向列表实现,对于出队和入队操作使用CAS非 ...
- 容器改变/窗口改变重新渲染echarts
是否遇见使用侧边栏菜单收缩/展开,echarts容器大小变化,但是echarts不重新自适应容器.或者,window窗口改变但是echarts不随着改变,针对这两种echarts不自适应的情况,分享下 ...
- 【记录】iconfont 批量把图标加入购物车的方法
iconfont 是阿里旗下很好用的图标管理网站(https://www.iconfont.cn/),里面有百万个小图标,可以随意下载切换颜色,是很多前端人员的选择. 但是网站没有将图标批量加入购物 ...
- WaitForSingleObject的作用[转]
在多线程的情况下,有时候我们会希望等待某一线程完成了再继续做其他事情(比如主线程等待子线程结束完之后,自己再结束),要实现这个目的,可以使用Windows API函数WaitForSingleObje ...
- kvm搭建
今日做公司项目时恰好是这个,然后就做一个博客,希望可以帮助到你们 1.把虚拟机zmedu63内存调成6G以上,因为我们要在VMware虚拟中安装KVM,然后在KVM中再安装虚拟机,需要内存大一些.zm ...