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)