Interference Signal

题目描述:

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

解题思路:

签到题。

AC代码:

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define INF 1e9+7; 
using namespace std;
int a[2005];
int main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,m;
		cin>>n>>m;
		int sum,k,ans=0;
		for(int i=0;i<n;i++)
			cin>>a[i];
		double ANS=0;
		for(m;m<=n;m++)
		{
			sum=0,k=0;
			for(int i=0;i<=n;i++)
			{
				if(k==m)
				{
					ans=max(ans,sum);
					sum-=a[i-m];
					k--;
				}
				sum+=a[i];
				k++;
			}
			ANS=(double)max((int)((double)ans/(double)m*1000.0),(int)ANS);
		}		
//		cout<<ans<<" "<<m<<endl;
		
		printf("%.0f\n",ANS); 
	}
	return 0;
}
发布了247 篇原创文章 · 获赞 53 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_42391248/article/details/89430243
今日推荐