Test instructions: Given an n, the following n number (assumed to be fi), requires the construction of a sequence of n number, so that the maximum length of each position of the sequence of ascending sub-sequence is equal to the corresponding fi.
In fact, this problem is a very simple question, before July also in BC to do, why write it, because the thinking process is very good.
Consider what conditions we need to construct such a sequence for each position? First of all, for a position where the position before the location, if their fi is greater than the position of the fi, then we give the position of the number must be less than the number of positions in the front, and for less than the position of the fi position, our values will be greater than their value, In other words, we have to make sure that the number of places that the fi is assigned to is large. So what about the same location for two fi? Must be the position of the back of the small distribution. Why, obviously, if you're big, you can add 1 to the length of the maximum ascending subsequence.
So this problem approach is out: to fi for the first keyword ascending, subscript for the second keyword descending, a sequence, and then corresponding to fill in the 1-n these numbers just fine.
1#include <bits/stdc++.h>2 using namespacestd;3 #defineN 1000054InlineintRead () {5 intx=0, f=1;CharA=GetChar ();6 while(a<'0'|| A>'9') {if(a=='-') f=-1; A=GetChar ();}7 while(a>='0'&& a<='9') x=x*Ten+a-'0', a=GetChar ();8 returnx*F;9 }Ten structdata{ One intNum,pos; A BOOL operator< (Constdata& W)Const{ - if(Num==w.num)returnPos>W.pos; - returnnum<W.num; the } - }a[n]; - intN,ans[n]; - intMain () { +n=read (); - for(intI=1; i<=n;i++) +A[i].num=read (), a[i].pos=i; ASort (A +1, A +1+n); at for(intI=1; i<=n;i++) -ans[a[i].pos]=i; - for(intI=1; i<=n;i++) -printf"%d", Ans[i]); - return 0; -}
Utr#2 T1