题意:计算一段时内,不少于连续k天最高的平均温度。The heat intensity value is the maximum of average temperatures over all segments of not less than kk consecutive days
题解:暴力 这道题坑点可能读题,没读好,昨晚一直wa8,这会看下,有精度误差,再看别人代码,不一定是除k,在仔细看题,发现是至少是k天,一直以为是计算k天温度的最大值。
c++:
include<bits/stdc++.h>
using namespace std;
double n,k,a[5010],sum,ans;
int main()
{
cin>>n>>k;
for(int i=1; i<=n; i++)
cin>>a[i],a[i]+=a[i-1];
for(int i=k; i<=n; i++)
for(int j=i;j<=n;j++)
ans=max(ans,(a[j]-a[j-i])*1.0/i);
cout<<fixed<<ans<<endl;
return 0;
}