NYOJ 1242 Interference Signal
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
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 6 int a[2005]; 7 8 int main() 9 { 10 int k,n,m; 11 scanf("%d",&k); 12 while(k--) 13 { 14 scanf("%d%d",&n,&m); 15 double aver=0.0; 16 memset(a,0,sizeof(a)); 17 for(int i=1;i<=n;i++) 18 { 19 scanf("%d",&a[i]); 20 a[i]+=a[i-1]; 21 } 22 for(int i=1;i<=n;i++) 23 for(int j=i+m-1;j<=n;j++) 24 { 25 double tmp=(a[j]-a[i-1])*1.0/(j-i+1); 26 aver=max(aver,tmp); 27 } 28 int ans=(int)(aver*1000); 29 printf("%d\n",ans); 30 } 31 return 0; 32 }