#P6366. [传智杯 #2 初赛] 特殊的翻转
[传智杯 #2 初赛] 特殊的翻转
Description
Teacher k is studying the code of a virus program. This code is information consisting of a hexadecimal string of length at most (that is, characters 0 to 9 and A to F). Now teacher k wants to convert it into a binary string (and at this time, you must ensure that the highest bit is ). Then, perform a “flip” operation on this string.
For each “flip” operation, teacher k can choose one position in the string, and flip this bit and its two adjacent bits (three bits in total) separately (that is, becomes , and becomes ). If the chosen position is at the beginning or the end of the sequence, then flip this bit and the existing adjacent bit(s).
Teacher k wants to know how to use the minimum number of “flip” steps to turn this string into an all- string.
Input Format
A hexadecimal string consisting of 0 to 9 and A to F.
Output Format
Output the minimum number of “flip” steps needed to turn it into an all- string. If it is impossible to turn it into an all- string no matter what, output No.
15
3
FF
3
10
No
Hint
Explanation of the samples:
Hexadecimal 15 corresponds to binary 10101. By flipping positions , it can all become .
Hexadecimal FF corresponds to binary 11111111. By flipping positions , it can all become .
Hexadecimal 10 corresponds to binary 10000, and it cannot be turned into all .
Translated by ChatGPT 5
京公网安备 11011102002149号