InterferenceSignal-----------挺简单的 一道题 就是英语不好

 1 InterferenceSignal
 2 时间限制: 2000ms内存限制: 128000KB 64位整型:      Java 类名:
 3 上一题  提交  运行结果  统计   讨论版  下一题
 4 类型: 
 5 没有
 6 
 7    添加
 8 题目描述
 9 Dr.Kong’s laboratory monitorsome interference signals. The interference signals can be digitized into aseries of positive integer. May be, there are N integers a1,a2,…,an.
10 
11  
12 
13 Dr.Kong wants toknow the averagestrength of a contiguous interference signal block. the block mustcontain at least M integers.
14 
15  
16 
17 Pleasehelp Dr.Kong tocalculate the maximumaverage strength, giventhe constraint.
18 
19 输入
20 The input contains K test cases. Each test case specifies:
21 * Line 1: Two space-separated integers, N and M.
22 * Lines2~line N+1: ai (i=1,2,…,N)
23 1 ≤ K≤ 8, 5 ≤ N≤ 2000, 1 ≤ M ≤ N, 0 ≤ ai ≤9999
24 输出
25 For each test case generate a single line containing a single integer that is 1000 times the maximal average value. Do not perform rounding.
26 样例输入
27 2 
28 10 6
29 6 
30 4
31 2
32 10
33 3
34 8
35 5
36 9
37 4
38 1
39 5 2
40 10
41 3
42 8
43 5 
44 9 
45 
46 样例输出
47 6500
48 7333
49 来源
50 NYOJ

第一行 两个数字   第一个数字代表 有多少个 数字信号   第二个代表  最少需要 几个 连续的信号  求其平均值 . 

 1 #include <stdio.h>
 2 #include <string.h>
 3 int main()
 4 {
 5     int ncase,a[2005];
 6     scanf("%d",&ncase);
 7     while(ncase--)
 8     {
 9         int n,m;
10         double sum,max=-0x3fffffff;
11         memset(a,0,sizeof(a));
12         scanf("%d %d",&n,&m);
13         for(int i=0;i<n;i++)
14         scanf("%d",&a[i]);
15         for(int i=0;i+m<=n;i++)
16         {
17             for(int k=m;k<=n&&i+k<=n;k++)
18             {
19                 sum=0;
20                 for(int j=0;j<k;j++)
21                     sum+=a[i+j];
22                 if(sum/k>max)
23                 max=sum/k;
24             }
25         }
26         printf("%d\n",(int)(max*1000));
27     }
28     return 0;
29 }

 

posted @ 2016-03-07 15:30  X-POWER  阅读(243)  评论(0编辑  收藏  举报