You’re playing an RPG, which is arguably the best Chinese RPG in 2007. You got to the final combat. You want to win as soon as possible. Do you know what I am talking about?
For competitors who're not familiar with the game: we're giving a brief introduction to the combat system and the characters involved in that last combat very soon.
For competitors who're too familiar with the game: we're simplifying and/or changing the rules and facts for this problem. We apologize if you feel unhappy about that.
Fig. The final combatThe screenshot above gives you some idea about the combat system and the characters, which can be summarized as follows:
You have 4 heroes: Yun Tianhe (YTH), Han Lingsha (HLS), Liu Mengli (LML) and Murong Ziying (MRZY). Before the combat begins, you need to choose exactly three heroes and rearrange them in some order. Let's call the 1st, 2nd and 3rd hero H1, H2 and H3, respectively. In this screenshot above, H1 is YTH, H2 is HLS and H3 is LML. (Sorry for the Ziying fans!)There are two bosses: Xuan Xiao (XX) and Su Yao (SY), both in the back of the screenshot.The goal of this combat is to defeat SY. In this problem, you can assume that XX is immortal, although it's possible to defeat him in the real game.The key to this problem is to understand the "semi" round-based combat system. See the
"progress bar" on the top of the screen? Each hero has a very small
progress ball (in light-blue) on the bar, with an icon above the ball. Similarly, each boss also has a ball (in red), but the icon is below the ball. When the combat begins, all the progress balls start moving from the left corner of the bar. When a ball reaches the right corner, the corresponding character is able to act. If more than one character can act, they make actions one by one, according to this precedence order: YTH, HLS, LML, MRZY, XX, SY. When a character is acting, all progress balls stopped moving. After a character finished an action, his/her progress ball is reset to the left corner of the progress bar. When nobody is acting, all progress balls go right simultaneously (but possibly with different speeds, see below).
In this problem, each character has 4 main properties: Jing, Qi, Shen, Su.
Jing means "health". When a character's Jing reaches zero or negative, he/she is defeated. A character's maximum Jing is denoted by parameter maxjing.Qi means "vitality". It is used by special-skill attacks. When Qi is not enough, certain special-skill attacks cannot be performed. A character's maximum Qi is always 100.Shen means "spirit". It is used by Xian Shu (something similar to, but more amazing than "magic"). When Shen is not enough, certain Xian Shu cannot be performed. A character's maximum Shen is denoted by parameter maxshen.Su means "speed". It affects how quick a character's progress ball moves. Su is always a positive integer less than 5. If a character's Su is x, it takes 5-x units time for his/her progress ball to move from left corner to the right corner of the progress bar. A character's Su (which is never changed during the combat) is denoted by parameter su.For simplicity, you may assume that both XX and SY use the same strategy:
In his/her (4n+1)-th action (n=0,1,2,...), make a weapon attack upon H1.In his/her (4n+2)-th action (n=0,1,2,...), make a weapon attack upon H2.In his/her (4n+3)-th action (n=0,1,2,...), make a weapon attack upon H3.In his/her (4n+4)-th action (n=0,1,2,...), make a special-skill attack upon all the heroes.Now we introduce four more parameters for each hero. The first two,
d1x and
d2x, are the damages that the hero takes on XX's weapon attack and special-skill attack, respectively. For SY's attacks, we define
d1s and
d2s similarly.
You’re very tired, so you don't want to waste your time designing complex tactics. When a hero is about to act, you only consider the following actions:
Make a physical weapon attack upon either XX or SY (cannot attack both). Be warned though, SY is surrounded by swords (see the screenshot), so making weapon attacks upon her would hurt the attacker himself/herself. The amount of "reflection damage" that the attacker takes is the same as the "physical damage" that SY takes. Attacking XX (yes, you can do that, if you like) does not suffer from physical reflection.Use Xian Shu to recover Jing. To make your brain easier, you decided not to recover other heroes' Jing. In this problem, the only Xian Shu that you can use is called "Yu Run", which recovers yurun_jing points of Jing (if the resulting Jing exceeds his/her maximum Jing, it is reduced to the maximum) and uses yurun_shen points of Shen.Use items to recover Shen. To make your brain easier, you decided not to recover other heroes' Shen. In this problem, the only item that you can use is called "Shu Er Guo", which recovers shuerguo_shen points of Shen (if the resulting Shen exceeds his/her maximum Shen, it is reduced to the maximum). You have an infinite number of Shu Er Guo.Make a special-skill attack if his/her Qi is enough. Each hero has exactly one special-skill attack, attacking both XX and SY. Note that some special-skill attacks are physical. Using a physical special-skill attack makes you take the same damage as SY, just like weapon attacks.Now it's time to introduce four more parameters for each hero:
wad,
ssd,
ssq and
ssp. The number of Jing points that SY takes by the hero's weapon attacks and special-skill attacks are denoted by
wad and
ssd, respectively. The special-skill attack is physical if and only if
ssp=1 (otherwise,
ssp=0). It needs
ssq points of Qi.
As you may have noticed, Qi cannot be recovered by Xian Shu or items. There are only two ways to increase Qi: make a weapon attack, or get hit by a weapon attack. Being hurt by physical reflection does
not earn you extra Qi.
So here come the last two parameters for each hero:
q1 and
q2, that means making a weapon attack increases
q1 points of Qi (whether or not you're reflected), while getting hit by a weapon attack increases
q2 points of Qi. If the resulting Qi exceeds his/her maximum Qi (which is always 100), it is reduced to the maximum. Again, performing a special-skill attack never increases your Qi. Getting hurt by the bosses' special-skill attacks never increases your Qi, either.
As a perfectionist, you don't want any hero to be defeated even temporarily (in the real game you can rebirth a hero with certain Xian Shu or items) - for example, it's
not allowed to make YTH and SY defeated at the same time (it can happen, for example, after YTH has performed a powerful physical special-skill attack).
Finally comes the question: what is the earliest time (we only care about ball-moving time, not including time needed to make attacks) that you can win the combat, if you play optimally? To play optimally, you need to choose between the options listed above, for each act. It's not as easy as it sounds. Be
careful!