第八届河南省程序设计大赛 Interference Signal

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 6
6 
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5 
9 

样例输出
6500
7333

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
    int k;
    cin>>k;
    while(k--)
    {
        int n,m;
        double p=0;
        cin>>n>>m;
        double a[2020]={0};
        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        for(int i=1;i+m-1<=n;i++){
            double sum1=0;
            for(int j=i;j<i+m-1;j++){
                sum1+=a[j];
            }
            for(int j=i+m-1;j<=n;j++){
                sum1+=a[j];
                if(sum1/(j-i+1)>p)p=sum1/(j-i+1);
            }
        }
        int k2=(int)(p*1000);
        printf("%d\n",k2);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_40788630/article/details/80169781
今日推荐