HDU 2993 MAX Average problem (slope DP entry)

Source: Internet
Author: User

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)

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.