903B - The Modcrab
2017-12-13 22:02
183 查看
B. The Modcrab
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health
points and an attack power of a2.
Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.
Vova's character has h1 health
points and an attack power of a1.
Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when
Vova drinks a potion. All potions are identical to each other. It is
4000
guaranteed that c1 > a2.
The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1)
or drink a healing potion (it increases Vova's health by c1; Vova's
health can exceed h1).
Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2.
The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's
attack.
Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.
Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.
Input
The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100)
— Vova's health, Vova's attack power and the healing power of a potion.
The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1)
— the Modcrab's health and his attack power.
Output
In the first line print one integer n denoting the minimum number of phases required to win the battle.
Then print n lines. i-th
line must be equal to HEAL if Vova drinks a potion in i-th
phase, or STRIKE if he attacks the Modcrab.
The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after
Vova's last action.
If there are multiple optimal solutions, print any of them.
Examples
input
output
input
output
Note
In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he
needs 3 strikes to win.
In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.
题意:vova要打败一个怪物,vova 的血量h1,攻击力a1,可以无限使用的血瓶c1,可以加c1这么多血,加的血量可以无上限。怪物的血量h2,攻击力a2。
有点像我们以前玩的回合制游戏,还挺好玩的,只是没有现在图像,特效,没有现在好。每回合voca只能攻击或者加血。让我们求出最少的回合打败怪物(怪物血量为1)。
题解:模拟就行。一开始没考虑,可以一击必杀的那种情况,就是h2怪物血量小于,vova攻击力并且vova血量小于怪物攻击力,其实不用加血的,直接秒杀!还有就是数组开
开到1e5,最开始我没注意看,以为就是100,就开了110的数组,一直TLE 第六组,懵圈的。没有考虑极端情况vova攻击力为和血瓶的大小都为1,而怪物的攻击力也为1,数组就不够用。
这里还有q神代码:
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab.
After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health
points and an attack power of a2.
Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle.
Vova's character has h1 health
points and an attack power of a1.
Also he has a large supply of healing potions, each of which increases his current amount of health points by c1 when
Vova drinks a potion. All potions are identical to each other. It is
4000
guaranteed that c1 > a2.
The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a1)
or drink a healing potion (it increases Vova's health by c1; Vova's
health can exceed h1).
Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a2.
The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's
attack.
Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases.
Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win.
Input
The first line contains three integers h1, a1, c1 (1 ≤ h1, a1 ≤ 100, 2 ≤ c1 ≤ 100)
— Vova's health, Vova's attack power and the healing power of a potion.
The second line contains two integers h2, a2 (1 ≤ h2 ≤ 100, 1 ≤ a2 < c1)
— the Modcrab's health and his attack power.
Output
In the first line print one integer n denoting the minimum number of phases required to win the battle.
Then print n lines. i-th
line must be equal to HEAL if Vova drinks a potion in i-th
phase, or STRIKE if he attacks the Modcrab.
The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after
Vova's last action.
If there are multiple optimal solutions, print any of them.
Examples
input
10 6 100 17 5
output
4 STRIKE HEAL STRIKE STRIKE
input
11 6 100 12 5
output
2 STRIKE STRIKE
Note
In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he
needs 3 strikes to win.
In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left.
题意:vova要打败一个怪物,vova 的血量h1,攻击力a1,可以无限使用的血瓶c1,可以加c1这么多血,加的血量可以无上限。怪物的血量h2,攻击力a2。
有点像我们以前玩的回合制游戏,还挺好玩的,只是没有现在图像,特效,没有现在好。每回合voca只能攻击或者加血。让我们求出最少的回合打败怪物(怪物血量为1)。
题解:模拟就行。一开始没考虑,可以一击必杀的那种情况,就是h2怪物血量小于,vova攻击力并且vova血量小于怪物攻击力,其实不用加血的,直接秒杀!还有就是数组开
开到1e5,最开始我没注意看,以为就是100,就开了110的数组,一直TLE 第六组,懵圈的。没有考虑极端情况vova攻击力为和血瓶的大小都为1,而怪物的攻击力也为1,数组就不够用。
#include<bits/stdc++.h> using namespace std; map<int,string>s; int main() { int h1,a1,c1,h2,a2,ans; int a[100010]={0}; s[0]="STRIKE",s[1]="HEAL"; scanf("%d%d%d%d%d",&h1,&a1,&c1,&h2,&a2); for(int i=1;;i++) { if(h2<=a1&&h1<=a2) { ans=i; ///秒杀情况,不用加血 break; } else { if(h1-a2<=0) { h1+=c1; a[i]=1; ///如果vov血量小于怪物攻击力,加血 h1-=a2; } else { h2-=a1; h1-=a2; } if(h2<=0) { ans=i; break; } } } printf("%d\n",ans); for(int i=1;i<=ans;i++) cout<<s[a[i]]<<endl; return 0; }
这里还有q神代码:
#include <cstdio> int A[100000]; int main(){ int n,a,b,c,d; scanf("%d%d%d%d%d",&n,&a,&b,&c,&d); while(c>0){ if(n>d||c<=a)c-=a,A[++A[0]]=0; else n+=b,A[++A[0]]=1; n-=d; } printf("%d\n",A[0]); for(int i=1;i<=A[0];++i) puts(A[i]?"HEAL":"STRIKE"); return 0; }
相关文章推荐
- 【Codeforces 903B】The Modcrab
- cf 903B - The Modcrab
- Codeforces 903B - The Modcrab 模拟+记录
- Educational Codeforces Round 34 (Rated for Div. 2)B. The Modcrab(贪心)
- G - The Modcrab
- B-The Modcrab
- The Modcrab_Codeforces
- [MODx] 1. Add Html5 template into the MODx
- What is the difference between SMOD and CMOD?
- iOS推送警告but you still need to add "remote-notification" to the list of your supported UIBackgroundMod
- OllyICE TheMida MOD. By EvOlUtIoN
- modules/mod_dav_svn.so into server: The specified module could not be found
- virtualbox报错,Please install the virtualbox-ose-dkms package and execute 'modprobe vboxdrv' as root
- Ceilometer - Install the API behind mod_wsgi
- “继承”与Data Member——《Inside The C++ Object Mod》学习笔记
- 【PowerDesigner】:Generation aborted due to errors detected during the verification of the mod
- Oracle Http Server安装mod_python,运行报错fatal: Not a git repository (or any of the parent directories)
- Apress.The.Definitive.Guide.to.Apache.mod.rewrite.Feb.2006.eBook
- compile the mod_gsoap of apache2 for win32
- Announcing the availability of ModSecurity extension for IIS