June 2021 C/C++ (Level 5) real test analysis#中国电子学院#National Youth Software Programming Level Examination

insert image description here

C/C++ Programming (Level 1~8) All real questions・Click here

Problem 1: Number Transformation

Given a string containing 5 digits (0-9), such as "02943", transform "12345" into it. There are 3 operations you can take to transform
(1) swap two adjacent numbers
(2) add 1 to a number. If it is greater than 9 after adding 1, it becomes 0
(3) doubles a number. If it is greater than 9 after doubling, it becomes the remainder of dividing the doubling result by 10.
You can only use the second type of operation 3 times at most, and the third type of operation 2 times to find the minimum number of operations to complete the transformation.
Time limit: 1000
Memory limit: 65536
inputs There are at most 100,000 sets of data. Each set of data is a string output
containing 5 numbers. For each set of data, output the minimum number of steps required to transform 12345 into a given string. If the conversion fails, output -1 sample input 12435 99999 12374 sample output 1 -1 3 Tips Because there are too many test data, if each set of data is searched from the beginning, it will be











Guess you like

Origin blog.csdn.net/gozhuyinglong/article/details/132549022