"Ningbo 23rd session of computer Program design Competition (junior group) T3" Horse (sort, longest not descending sub-sequence)

Source: Internet
Author: User

Title description Ares Ares heard in 2008 in the Chinese land, will hold a large-scale Olympic games, heart circumnavigated unusually excited, he summoned N-bit days will, riding their own tianma, ready in the vast sky, held an unprecedented day will parade. Tianma in the familiar with their own days will later, is already the horse in one, can not separate. Ares wants to select as many Pegasus and days as possible in these n Pegasus and N days to form a queue that must satisfy both:
(1) The height of the queue and the height of the Tianma and the altitude, the latter one should be larger than the previous one.
(2) in the queue after a Tianma height is not lower than the previous Tianma height, the queue after a day will be height not less than the previous day will be high.
What should be the choice to make the queue the maximum length? Can you give Ares the staff of Ares? Input

The first line of the input file horse.in has only a positive integer n, which represents a total of n horses and N days to be.
The second line has n positive real numbers, each of which represents the height of each Tianma, and the number of I indicates the height of the Pegasus. The n number is separated from each other by a space.
The third row has n positive real numbers, each representing the height of each day, and the number of I for the first day. The n number is separated from each other by a space.

There is only one row in the output output file Horse.out, and the line has only a positive integer, which is the longest queue length that meets the criteria. According to the height of the horse, if you find the adjacent two horses and the same height, then "delete" This node, and then row again. Since the height of the horse is now lined up, we only need to ask for the longest non-descending subsequence determined by the general's height.
1#include <algorithm>2#include <cstdio>3  4 structfighters{5     floath,f;6}a[9001];7  8 intn,ans,tot=1;9 floatmaxn,f[9001];Ten #defineMax (x, y) (x>y?x:y) One   A BOOLCMP (Fighters x,fighters y) { -     if(X.h==y.h)returnx.f<y.f; -     returnx.h<Y.h; the } -   - intMainvoid){ -scanf"%d",&n); +      for(intI=1; i<=n;++i) -scanf"%f",&a[i].h); +      for(intI=1; i<=n;++i) Ascanf"%f",&a[i].f); atStd::sort (A +1, a+n+1, CMP); -      for(intI=1; i<n;++i) -         if((a[i].f==a[i+1].F) && (a[i].h==a[i+1].h)) -a[i].f=Ten; -Std::sort (A +1, a+n+1, CMP); -f[1]=a[1].f; in      for(intI=2; i<=n;++i) { -         if(a[i].f>=F[tot]) { tof[++tot]=a[i].f; +             Continue; -         } the         intJ=std::upper_bound (f+1, f+tot+1, A[I].F)-F; *f[j]=a[i].f; $     }Panax Notoginsengprintf"%d", tot); -}

"Ningbo 23rd session of computer Program design Competition (junior group) T3" Horse (sort, longest not descending sub-sequence)

Related Article

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.