题目链接:http://nyoj.top/problem/1242
- 内存限制:64MB 时间限制:2000ms
题目描述
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 6
6
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5
9
样例输出
6500
7333
解题思路
题意:求连续序列大于等于k个的最大平均值。
思路:数据比较水,直接暴力就完事了,注意输出的时候不要四舍五入。
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m, a[2005];
scanf("%d", &t);
while (t--) {
double sum, max_ = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i <= n - m; i++) {
for (int j = m; j <= n - i; j++) {
sum = 0;
for (int k = i; k < i + j; k++)
sum += a[k];
max_ = max(max_, sum / j);
}
}
printf("%d\n", (int)(max_ * 1000));
}
return 0;
}