第八届河南省程序设计大赛 1242-Interference Signal(java)

1242-Interference Signal


内存限制:64MB  时间限制:2000ms  Special Judge: No

accepted:2  submit:5

题目描述:

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


提示:

没有提示哦

来源


这道题只要注意好长度最小是m,和生成的是整数。

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int q=sc.nextInt();
		while(q-->0){
			int n=sc.nextInt();
			int m=sc.nextInt();
			int[] a=new int[n];
			for(int i=0;i<n;i++){
				a[i]=sc.nextInt();
			}
			double max=-1;
			for(int i=0;i+m<=n;i++){
				for(int j=m;j<=n&&i+j<=n;j++){
					double sum=0;
					for(int k=0;k<j;k++){
						sum+=a[i+k];
					}
					if(sum/j>max){
						max=sum/j;
					}
				}
			}
			System.out.println((int)(max*1000));
		}

	}

}

猜你喜欢

转载自blog.csdn.net/hui_1997/article/details/80171844
今日推荐