#P15105. [ICPC 2025 LAC] Keep Fighting
[ICPC 2025 LAC] Keep Fighting
题目描述
Bob is playing a card game where he must defeat a monster. Before the game starts, Bob's power is set to , the monster's health is set to , and Bob receives a deck of cards in his hands.
Each card in the deck belongs to one of the following types:
- Multiply: a card of this type has a number written on it. Playing it multiplies Bob's current power by .
- Add: a card of this type also has a number written on it. Playing it increases Bob's current power by .
- Attack: a card of this type allows Bob to attack the monster. Playing it reduces the monster's current health by Bob's current power.
The game is played in turns. In each turn, Bob must play exactly one card from his hand, after which the card is moved to a discard pile. If Bob has no cards left in his hand at the end of a turn, he retrieves all cards from the discard pile and can use them again in any order.
The monster is beaten as soon as its health reaches or less. Is it possible for Bob to beat the monster? If so, what is the minimum number of turns required?
输入格式
The first line contains three integers (), () and (), indicating respectively the number of cards in the deck, Bob's initial power and the monster's initial health.
Each of the next lines describes a card. The content of the line depends on the type of the card, as follows:
- Multiply: the line contains the character “*” (asterisk) and an integer (), representing the multiply factor provided by the card.
- Add: the line contains the character “+” (plus sign) and an integer (), indicating the increment provided by the card.
- Attack: the line contains the character “!” (exclamation mark).
输出格式
Output a single line with an integer indicating the minimum number of turns required to beat the monster, or the character “*” (asterisk) if it is impossible to beat the monster.
3 0 20
* 2
!
+ 5
4
1 0 1
!
*
1 1 1
+ 1
*
提示
Explanation of sample 1:
To beat the monster in 4 turns, Bob can play as follows:
- Bob plays the card, so his power becomes .
- Bob plays the card, so his power becomes .
- Bob plays the card, so the monster's health becomes . Since now Bob has no cards in his hands, all three cards go back to him.
- Bob plays the card, so the monster's health becomes , and the monster is beaten.