Problem 2184 Reverse number restore
Accept:8 submit:15
Time limit:1000 mSec Memory limit:32768 KB
Problem Description
For a while Eric was interested in the number of reverse numbers, and he began to solve many of the sequence's reverse numbers (for an array of arrays A of 1...N, the number of reverse order is the number of I<j,ai>aj), but one day he found himself missing the original sequence, Just leave the reverse number of the numbers that were left in the previous calculation, and now you can help him restore the original sequence. Input
There are multiple sets of data, please handle to end of file.
The first behavior of each set of data is an integer N (1<=n<=1000) that represents the number of digits in the sequence.
The second behavior is n integers, and the number of digits in the AI is smaller than the AI. Output
The
Output is a row of n integers, representing the original series. sample Input 5 2 0 1 0 0 sample Output 3 1 4 2 5
Although it's a very simple question for a lot of people. , but I thought for a long time also did not think out, and the beginning of my ideas are wrong, perhaps the logic of the poor because of the reason it, to tell the truth inside really have a snack rub. I really want to be strong, but more than I am smarter than I work people still have so much, I do not know how to do, no longer consider the eyes of others, brave to go forward.
The problem looks complicated, but it's regular, just take the example, the first number you enter is 2, which means that only 2 of the following is smaller than it is, then it must be 3, and then in the original array to remove the 3 tag, then the second is 0, then the back is bigger, then it must be 1, The third one is 1, then there are 1 numbers smaller than the current one, then 4, and so on. The
is actually regular, putting 1~n these numbers in an array that starts with 0, and then sort them every time, then output the number corresponding to the first subscript in input, then clear the array, and then proceed to sort.
Note that each excluded number is marked as a positive infinity or a large number.
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream >
using namespace std;
int main () {
int n,i,j,k;
int a[1111],ss[1111];
while (~SCANF ("%d", &n)) {
memset (a,0,sizeof (a)); memset (ss,0,sizeof (ss));
for (i=0;i<n;i++)
ss[i]=i+1;
for (i=0;i<n;i++)
cin>>a[i];
for (i=0;i<n;i++) {
sort (ss,ss+n);
if (i!=n-1) {
printf ("%d", Ss[a[i]]);
ss[a[i]]=n+1;
}
else printf ("%d\n", Ss[a[i]]);}}