Interference Signal
时间限制:
2000 ms | 内存限制:
65535 KB
难度:
1
-
描述
-
Dr.Kong’s laboratory monitor some interference signals. The interference signals can be digitized into a series of positive integer. May be, there are 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.
Please help Dr.Kong to calculate the maximum average strength, given the 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 66 42103859415 210385 9
样例输出
-
65007333
来源
-
第八届河南省程序设计大赛
-
The input contains K test cases. Each test case specifies:
输出的时候有坑,浪费了半个多小时。。。 输出不能用printf("%.lf\n", max*1000); 要用%d输出
#include<stdio.h>
int main() {
int k, n, m, a[2005], count, con;
scanf("%d", &k);
while(k--) {
double ave, max = -1.0;
scanf("%d%d", &n, &m);
for(int i = 0; i < n; i++)
scanf("%d", &a[i]);
count = m;
for(int t = 0; t <= n-m; t++) {
for(int i = 0; i <= n-m && i+count <= n; i++) {
double sum = 0.0;
for(int j = i; j < count+i; j++) {
sum += a[j];
//printf("%d ", a[j]);
}
ave = sum/count;
if(ave > max) max = ave;
//printf(" sum = %lf count = %d 平均值是:%lf\n", sum, count, ave);
}
count++;//控制求平均值数的个数
}
printf("%d\n", (int)(max*1000));
}
}
这种题还是自己做比较好 循环控制条件不自己去试不容易看懂