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 ...
随机推荐
- luoguP1083 借教室(题解)(我用的线段树)
luoguP1083 借教室 题目 #include<cstdio> #include<iostream> #include<cmath> #include< ...
- ubantu18.04中mysql8.0设置远程连接的问题
在mysql8.0中的配置文件中默认是没有绑定地址的,但是可以自己配置,在my.cnf中 这里使用另一种方式: 首先先连接到自己的数据库执行: use mysql; select host,user ...
- K8S操作
一.K8Spods操作 kubectl delete all --all //删除 所有pods
- 2019牛客多校第五场F maximum clique 1 最大独立集
题意:给你n个数,现在让你选择一个数目最大的集合,使得集合中任意两个数的二进制表示至少有两位不同,问这个集合最大是多大?并且输出具体方案.保证n个数互不相同. 思路:容易发现,如果两个数不能同时在集合 ...
- EnumPrinters
https://blog.csdn.net/jilong17/article/details/6663734 已解决.开始hook的spoolss.dll里面的EnumPrinterW函数,应该hoo ...
- error: device unauthorized.
1 执行 adb install com.taobao.taobao_250.apk 报错 2 先看手机是不是未授权,执行命令之后,手机回弹出授权信息,点击确认就行了
- 51单片机外部中断INT0实例(汇编程序)
;普中51开发板 ;单片机的P3.2(INT0)引脚与按键K3脚连接 ;用汇编语言实现:按一次K1外部中断INT0响应一次,LED显示值加1(十进制), ;前提是共阴数码LED第一位,需要设定,由P0 ...
- Rectangle类详解
一,概括: 乍一看,可能感觉是一个矩形类,矩形类就是画一个长方形吗??这是我一开始见到这个类的感觉. 其实不是的Rectangle是一个“区域”类,它的最大作用就是定义一个矩形的区域,如果问为什么是矩 ...
- Java 设计模式-【单例模式】
单例解决了什么问题:为了节约系统资源,有时需要确保系统中某个类只有唯一一个实例,当这个唯一实例创建成功之后,我们无法再创建一个同类型的其他对象,所有的操作都只能基于这个唯一实例.为了确保对象的唯一性, ...
- 匹配Luhn算法:可用于检测银行卡卡号
匹配Luhn算法:可用于检测银行卡卡号 /** * http://www.cnblogs.com/JnKindle/p/5798974.html * * 匹配Luhn算法:可用于检测银行卡卡号 * * ...