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 ...
随机推荐
- 安装vue开发环境→安装淘宝镜像的时候报错
问题: npm WARN deprecated socks@1.1.10: If using 2.x branch, please upgrade to at least 2.1.6 to avoid ...
- JavaFx开发桌面软件
JavaFx开发桌面软件 */--> code {color: #FF0000} pre.src {background-color: #002b36; color: #839496;} Jav ...
- C# 与 C++ 互操作(C# 调用 C++ 的动态链接库)
1.新建 C++ 动态链接库项目 CPlus.cpp: #include "stdafx.h" extern "C" __declspec(dllexport) ...
- C#用new和override来实现抽象类的重写区别
一,抽象的实现 using System; using System.Collections.Generic; using System.Linq; using System.Text; namesp ...
- Pycharm 激活码2017最新
BIG3CLIK6F-eyJsaWNlbnNlSWQiOiJCSUczQ0xJSzZGIiwibGljZW5zZWVOYW1lIjoibGFuIHl1IiwiYXNzaWduZWVOYW1lIjoiI ...
- SQL数据库—<10>--查询练习题
待整理···· 45题.分页查询 学生选课数据库SQL语句练习题(45个题) 练习题网盘地址:点我 create database xxb go use xxb go --表(一)Student (学 ...
- docker 安装Filebeat
1.查询镜像 docker search filebeat 2.拉取镜像 我此处选择的是prima/filebeat docker pull prima/filebeat 3.创建配置文件 fileb ...
- Nginx的应用之安装配置
一.Nginx简述 Nginx是一个开源且高性能.可靠的Http Web服务.代理服务. 开源: 直接获取源代码 高性能: 支持海量并发 可靠: 服务稳定 我们为什么选择 Nginx服务 Nginx非 ...
- 链表反转&交换链表结点
leetcode链表反转链接 要求摘要: 反转一个单链表 输入: 1->2->3->4->5->NULL 输出: 5->4->3->2->1-&g ...
- opengl 库glew
OpenGL OpenGL是个专业的3D程序接口,是一个功能强大,调用方便的底层3D图形库.OpenGL的前身是SGI公司为其图形工作站开发的IRIS GL.IRIS GL是一个工业标准的3D图形软件 ...