CSU 1553:good subsequence (longest continuous sub-sequence)

Source: Internet
Author: User

Http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2071&pid=6

Test instructions: There is a sequence consisting of n number

Requires a sequence that satisfies Max-min<=k's eldest son.

Idea: (I heard that the data big situation can be solved with a monotone stack but I was purely violent)

First, enumerate the left bounds and assign Max and Min both to a[i]

Then enumerate the right bounds each time to determine whether max-min is less than or equal to K

Find the maximum value

 #include <cstdio> #include <iostream> #include <cstring># include<cmath> #include <stdlib.h> #include <algorithm> #include <queue> #include <stack    > #include <ctype.h>using namespace std;int a[10000+100];int main () {int n,k;    int i,j;        while (scanf ("%d%d", &n,&k)!=eof) {int ans=1;        for (i=0;i<n;i++) scanf ("%d", &a[i]);            for (i=0;i<n;i++) {if (N-i<ans) break;            int temp=1;            int maxx=a[i];            int minn=a[i];                for (j=i+1;j<n;j++) {if (A[j]>maxx) {maxx=a[j];                } else if (A[j]<minn) {minn=a[j];                } if (maxx-minn>k) break;            temp++;        } if (ans<temp) ans=temp;    } printf ("%d\n", ans); } return 0;} 

  

CSU 1553:good subsequence (longest continuous sub-sequence)

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.