Face questions
Title Description
Man finally boarded the Martian land and saw the mysterious Martian. Humans and Martians can not understand each other's language, but our scientists have invented a method of digital communication. This exchange method is that, first of all, the Martians to a very large number of human scientists tell scientists break up the meaning of this number, then a very small number of large numbers added to the above, the results tell Martian, as a human answer.
Martian in a very simple way to represent numbers - snapping fingers. Martian only one hand, but only the hands of tens of thousands of fingers, the fingers in a row, numbered \ (1,2,3 ... \) . Martian any two fingers can freely exchange position, they are counted by this method.
A Martian with a human hand shows how to count with your fingers. If the five finger - thumb, index, middle, ring and little fingers are numbered \ (1,2,3,4 \) and \ (5 \) , when they are arranged in the normal order, the formation of \ (5 \) digits \ (12345 \) when you swap position ring finger and little finger, will form \ (5 \) digits \ (12354 \) when you order five fingers turned upside down, will form \ (54321 \) , can be formed in all of the \ (120 \) a \ (5 \) bit number, \ (12345 \) minimum, which represents \ (1 \) ; \ (12354 \) second small, it represents \ (2 \) ; \ (54321 \) maximum, which indicates \ (120 \) . The following table shows only \ (3 \) when the fingers are able to form (6 \) \ a \ (3 \) digits and numbers they represent:
Ternary number
\(123\)
\(132\)
\(213\)
\(231\)
\(312\)
\(321\)
Figures represent
\(1\)
\(2\)
\(3\)
\(4\)
\(5\)
\(6\)
Now you lucky enough to be the first people on earth and Mars to communicate with people. A Martian will let you see his fingers, scientists will tell you to go together very small numbers. Your task is, the number of scientists Martian represented with a finger to tell you the numbers together, and change the order of Martian fingers according to result of the addition. Input data to ensure that the results are not beyond the scope of Martian fingers can be represented.
Input and output formats
Input Format
A total of three lines. The first line a positive integer \ (N \) , representing the number of Martian fingers ( \ (1 \ Le N \ Le 10000 \) ). The second line is a positive integer \ (M \) , said to add to a small integer ( \ (. 1 \ Le M \ Le 100 \) ). The next line is \ (1 \) to \ (N \) This \ (N \) th arrayed integers a, separated by spaces, Mars represents the order of the fingers.
Output Format
\ (N \) integers, Mars represents the order after the change of the finger. Every two adjacent intermediate numbers separated by a space, you can not have extra space.
Sample input and output
Input Sample # 1
5
3
1 2 3 4 5
Sample Output # 1
1 2 4 5 3
Explanation
For 30% of the data, \ (N \ Le 15 \) ;
for 60% of the data, \ (N \ Le 50 \) ;
for all the data, \ (N \ Le 10000 \) ;
noip2004 popularity of Group 4 questions
analysis
At that noip STL
disabled era, this question is equivalent to a handwritten whole arrangement yysy
, very difficult test of thinking.
but
Reach came the congratulatory message
This year both 0202
years, STL
would have re-opened, with std :: next_permutation
this question how much water to water.
About std :: next_permutation
the details, you can go cppreference
see.
Ah I know you are waiting for the link, qwq
give you a portal ⑧: Portal .
There std :: prev_permutation
and std :: is_permutation
, I guess you must wait another portal, hey hey, crab is to say a person, which gives: std :: prev_permutation , std :: is_permutation
on so many portals, but also code time
the.
Code
#include <iostream>
#include <cstdio>
#include <algorithm>
const int maxn = 10005;
int a[maxn];
int main() {
int n,m;
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
while(m--) std :: next_permutation(a + 1,a + n + 1);
for(int i = 1; i <= n; i++) printf("%d ",a[i]);
printf("\n");
return 0;
}
Evaluation results
AC 100
: R30998999
my best ever rid
eh!