Time limit: 10000ms single point time limit: 1000ms memory limit: 256MB description
Little Ho has developed a Hiho password based on the knowledge he learned recently in cryptography, and the secret key for this password is generated: for a language with n letters, select a word of M length; write all the letters that make up the word in sequence (i.e., skipping when the same letter is encountered) And then arrange the remaining letters of the alphabet in the order they are left behind.
For a 5-letter Hiho, select the word 1, 2, 2, 4, 3 (where the numbers denote the order of the letters in the alphabet), and the secret key is 1,2,4,3,5.
But one day, after figuring out the secret key, Little Ho found out that he had lost the first word he had chosen, so he found you, hoping you could help him find the shortest word that could generate the secret key.
Input
Each input file contains a single set of test data.
The first behavior of each set of test data is a positive integer n, meaning as described earlier.
The second behavior of each set of test data n positive integers, used to describe a secret key where the i-positive integer AI represents the order of the I-character of the secret key in the alphabet.
For 100% of data, meet N<=1000,1<=ai<=n.
For 100% of the data, meet for any 1<=i, j<=n, if i≠j, then Ai≠aj.
Output
For each set of test data, the output is able to generate the shortest word (the empty string is not considered a word) of the secret key given by the input. Because the alphabet is not given, the order of the letters in the alphabet (separated by spaces) is printed for each letter.
-
-
Sample input
-
-
51 2 4) 3 5
-
-
Sample output
-
1 2 4
Idea: Too much water, direct storage code got;
AC Code:
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespacestd;inta[1010],vis[1010];intMain () {intN; scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%d",&A[i]); } intflag=1; for(inti=n-1;i>0; i--) { if(a[i]>=a[i+1]) {flag=i; Break; } } for(intI=1; i<=flag;i++) {printf ("%d", A[i]); } return 0;}
hihocoder-1283 hiho Password (water problem)