记录编号 |
121985 |
评测结果 |
AAAAAAAAAA |
题目名称 |
[USACO Mar03]最大平均值 |
最终得分 |
100 |
用户昵称 |
HouJikan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.129 s |
提交时间 |
2014-09-22 09:56:56 |
内存使用 |
1.08 MiB |
显示代码纯文本
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <list>
#include <vector>
#include <ctime>
#include <iterator>
#include <functional>
#define pritnf printf
#define scafn scanf
#define For(i,j,k) for(int i=(j);i<=(k);(i)++)
using namespace std;
typedef long long LL;
typedef unsigned int Uint;
const int INF=0x7ffffff;
//==============struct declaration==============
//==============var declaration=================
const int MAXN=100010;
double S[MAXN],res=-INF;
deque <int> Q;
int n,k;
//==============function declaration============
//==============main code=======================
int main()
{
string FileName="avanum";//程序名
string FloderName="COGS";//文件夹名
freopen((FileName+".in").c_str(),"r",stdin);
freopen((FileName+".out").c_str(),"w",stdout);
#ifdef DEBUG
system(("cp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\standard.cpp C:\\Users\\Administrator\\Desktop\\"+FloderName+"\\submit.txt").c_str());
clock_t Start_Time=clock();
#endif
scanf("%d%d",&n,&k);
memset(S,0,sizeof(S));
For(i,1,n)
{
scanf("%lf",S+i);
S[i]+=S[i-1];
}
For(i,k,n)
{
while (!Q.empty()&&Q.front()>i-k)
Q.pop_front();
while (!Q.empty()&&(S[i]-S[Q.back()-1])/(i-Q.back()+1)<(S[i]-S[i-k])/k)
Q.pop_back();
Q.push_back(i-k+1);
res=max(res,(S[i]-S[Q.front()-1])/(i-Q.front()+1));
}
printf("%d\n",int(res*1000));
#ifdef DEBUG
clock_t End_Time=clock();
printf("\n\nTime Used: %.4lf Ms\n",double(End_Time-Start_Time)/CLOCKS_PER_SEC);
#endif
return 0;
}
//================fuction code====================