Utr#2 T1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.