Interference Signal
时间限制:2000 ms | 内存限制:65535 KB
难度:1
-
描述
-
Dr.Kong’s laboratory monitorsome interference signals. The interference signals can be digitized into aseries of positive integer. May be, there are N integers a1,a2,…,an.
Dr.Kong wants toknow the averagestrength of a contiguous interference signal block. the block mustcontain at least M integers.
Pleasehelp Dr.Kong tocalculate the maximumaverage strength, giventhe constraint.
-
输入
-
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
输出
- For each test case generate a single line containing a single integer that is 1000 times the maximal average value. Do not perform rounding. 样例输入
-
2 10 6 6 4 2 10 3 8 5 9 4 1 5 2 10 3 8 5 9
样例输出
-
6500
-
7333
#include <stdio.h> #define Max_N 2001 int s[Max_N]; int Max(double a,double b) { return a>b?a:b; } int main() { int T; scanf("%d",&T); while(T--) { int m,n,g; scanf("%d%d",&n,&m); int i,j; s[0] = 0; for(i=1;i<=n;i++) { scanf("%d",&g); s[i] = s[i-1] + g; } double sum = -0x3f3f3f3f,max; for(i=0;i<n;i++) { for(j=i+m;j<=n;j++) { max = (s[j]-s[i])*1.0/(j-i)*1000; sum = Max(max,sum); } } printf("%d\n",(int)sum); } return 0; }
-
The input contains K test cases. Each test case specifies: