Topic 1242 topic Information running results Discussion area
Interference SignalTime limit: Ms | Memory limit: 65535 KB Difficulty: 1 description
Dr.kong ' s laboratory monitor some interference signals. The interference signals can is digitized into a series of positive integers. May is, there is N integers a1,a2,..., an.
Dr.kong wants to know the average strength of a contiguous interference signal block. The block must contain at least M integers.
Dr.kong to calculate the maximum average strength, given the constraint. Enter the input contains K test cases. Each test case specifies:
* Line 1:two space-separated integers, N and M.
* Lines2~line N+1:ai (i=1,2,..., N)
1≤k≤8, 5≤n≤2000, 1≤m≤n, 0≤ai≤9999
Output for each test case generate a single line containing a single integer this is the maximal average value. Do not perform rounding. Sample input
Sample output
65007333
Source eighth session of Henan Province Program design Contest uploader
Hnu_acm
Two notes one is an at least one is do not perform rounding.
#include <stdio.h>
#include <string.h>
int main ()
{
int ncase,a[2005];
scanf ("%d", &ncase);
while (ncase--)
{
int n,m;
Double sum,max=-0x3fffffff;
memset (A,0,sizeof (a));
scanf ("%d%d", &n,&m);
for (int i=0;i<n;i++)
scanf ("%d", &a[i]);
for (int i=0;i+m<=n;i++)
{for
(int k=m;k<=n&&i+k<=n;k++)
{
sum=0;
for (int j=0;j<k;j++)
sum+=a[i+j];
if (Sum/k>max)
max=sum/k;
}
}
printf ("%d\n", (int) (max*1000));
}
return 0;
}