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 4210385941
5 2
10385 9 
样例输出
6500
7333
来源
第八届河南省程序设计大赛

AC代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
    int M,N,K;
	int a[2010];
	int i,j,k;
	double sum,s;
    while(cin>>K)
    while(K--){
        cin>>N>>M;
        for(i=0;i<N;i++)
		scanf("%d",&a[i]);
		s=0;
        for(i=0;i+M<=N;i++)//控制开始位置
        {
            for(k=M;i+k<=N;k++)//求和区间
            {
                sum=0.0;
                for(j=0;j<k;j++)
                sum+=a[i+j];
                s=max(sum/k,s);
            }
        }
        printf("%d\n",(int)(s*1000));
    }
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值