#P2708. 硬币翻转
硬币翻转
Description
There are many coins placed in a row. Heads-up is represented by , and tails-up is represented by .
Starting from the first coin in the row, in each operation you must flip the first several coins simultaneously, i.e., choose some and flip the first coins. What is the minimum number of such operations needed to make all coins heads-up?
Input Format
A string consisting of and , representing the initial state of the coins.
Output Format
An integer, the minimum number of flips required.
10
2
Hint
Sample Explanation
For example, for input 10:
- The -st flip: flip the first coin to tails; the string becomes 00.
- The -nd flip: flip the first and second coins together to heads; the string becomes 11. Flipping is complete, so the output is .
Constraints
Let be the total number of coins.
- For of the testdata, .
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号