【例57.3】火星人
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
Description
Humans have finally set foot on Mars and encountered mysterious Martians. Neither humans nor Martians can understand each other's language, but our scientists have invented a method of communication using numbers. This method works as follows: first, a Martian tells a human scientist a very large number. After the scientist deciphers the meaning of this number, they add a small number to it and tell the result to the Martian as a human response.
Martians represent numbers in a very simple way—by counting on their fingers. A Martian has only one hand, but this hand has thousands of fingers, arranged in a row and numbered , , , and so on. Martians can freely swap the positions of any two fingers, and this is how they count.
A Martian demonstrated how to count on fingers using a human hand. If five fingers—thumb, index, middle, ring, and little finger—are numbered , , , , and , respectively, when arranged in the normal order, they form the -digit number . When you swap the ring and little fingers, it forms the -digit number . When you completely reverse the order of the five fingers, it forms . Among all possible -digit numbers, is the smallest, representing ; is the second smallest, representing ; and is the largest, representing . The table below shows the -digit numbers that can be formed with only fingers and the numbers they represent:
Ternary numbers represent numbers .
Now, you have the honor of being the first Earthling to communicate with a Martian. A Martian will show you their fingers, and a scientist will tell you a small number to add. Your task is to add the number represented by the Martian's fingers to the number told by the scientist and change the order of the Martian's fingers according to the result. The input data guarantees that this result will not exceed the range that the Martian's fingers can represent.
Input Format
Three lines: the first line contains a positive integer , representing the number of Martian fingers (). The second line contains a positive integer , representing the small integer to be added (). The next line contains a permutation of the integers from to , separated by spaces, representing the order of the Martian's fingers.
Output Format
A single line containing integers, representing the new order of the Martian's fingers. Each adjacent pair of numbers should be separated by a single space, with no extra spaces.
Sample
5
3
1 2 3 4 51 2 4 5 3
20251025D班作业(4)
- Status
- Done
- Problem
- 12
- Open Since
- 2025-10-26 0:00
- Deadline
- 2025-11-3 23:59
- Extension
- 24 hour(s)