poj 2018 分类: poj 2015-04-22 13:48 32人阅读 评论(0) 收藏
题意:在所有长度大于等于m的区间中找一个平均值最大的,输出平均数。
solution:
对于
1.
2.
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
const int MAXN = 1e5+5;
int n, m;
int c[MAXN] = {0}, sum[MAXN] = {0};
int f[MAXN] = {0}, num[MAXN] = {0};
int ans = 0;
int main()
{
#ifndef ONLINE_JUDGE
freopen("poj2018.in","r",stdin);
freopen("poj2018.out","w",stdout);
#endif
std::cin >> n >> m;
for(int i = 1; i <= n; i++)
{scanf("%d",c+i); sum[i] = sum[i-1]+c[i];}
f[m] = sum[m], num[m] = m;
for(int i = m+1; i <= n; i++)
{
f[i] = sum[i] - sum[i-m] ,num[i] = m;
if((f[i-1]+c[i])*num[i] > f[i]*(num[i-1]+1) )
f[i] = f[i-1]+c[i], num[i] = num[i-1]+1;
}
for(int i = m; i <= n; i ++)
ans = std::max(ans, f[i]*1000/num[i]);
std::cout << ans << std::endl;
#ifndef ONLINE_JUDGE
fclose(stdin);
fclose(stdout);
#endif
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。