Title Link: hdu 2993 MAX Average problem
Test instructions
For a sequence of length n, find the maximum continuous subsequence of the average length >= K.
Exercises
This is the original title of the paper, please refer to the 2004 set of training team paper "Zhou Yuan--A brief discussion on the application of the idea of combination of numbers and shapes in the competition of informatics"
This input is a bit large, to be read into the optimization before.
1#include <bits/stdc++.h>2 #defineF (I,A,B) for (int i=a;i<=b;++i)3 using namespacestd;4 5 inttot;6 Const intbuf=25000000;7 Charbuf[buf],*buf=Buf;8InlinevoidReadint&a) { for(a=0;*buf< -; buf++); while(*buf> -) a=a*Ten+*buf++- -;}9 Ten Const intn=1e5+7; One intsum[n],q[n],n,k; A -InlineintUseless (intAintBintc) - { the return1ll* (Sum[c]-sum[b]) * (b-a) <=1ll* (Sum[b]-sum[a]) * (C-b); - } - - intMain () + { -Tot=fread (Buf,1, Buf,stdin); + while(1) A { at if(buf-buf+1>=tot) Break; - read (n), read (k); -F (I,1, n) read (Sum[i]), sum[i]+=sum[i-1]; - intHead=1, tail=0; - Doubleans=0; - F (i,k,n) in { - while(Head<tail&&useless (q[tail-1],Q[TAIL],I-K)) tail--; toq[++tail]=i-K; + while(Head<tail&&useless (q[head+1],q[head],i)) head++; -Ans=max (ans, (sum[i]-sum[q[head]) *1.0/(I-Q[head])); the } *printf"%.2f\n", ans); $ }Panax Notoginseng return 0; -}View Code
HDU 2993 MAX Average problem (slope DP entry)