nyoj 1242 Interference Signal(暴力枚举)
2017-04-24 08:33
309 查看
描述
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
来源
第八届河南省程序设计大赛
ps:被水题卡了好久,,忽然灵光一现,直接枚举选多少个就好了。。。
代码:
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
来源
第八届河南省程序设计大赛
ps:被水题卡了好久,,忽然灵光一现,直接枚举选多少个就好了。。。
代码:
#include<stdio.h> #define Max(a,b) (a>b?a:b) #define maxn 2010 int a[maxn]; int main() { int t,n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i=1; i<=n; ++i) scanf("%d",&a[i]); double maxx=0.0; for(int i=m; i<=n; ++i) { double tmp=0; int k=0; for(int j=1; j<=n; ++j) { tmp+=a[j]; ++k; if(k==i) { double tot=tmp*1.0/i; maxx=Max(tot,maxx); tmp=tmp-a[j-k+1]; --k; } } } printf("%d\n",(int)(maxx*1000)); } return 0; }
相关文章推荐
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj 1242 Interference Signal(暴力枚举)
- nyoj Wythoff Game(暴力枚举)
- nyoj 7 街区最短路径问题 暴力枚举
- UVA 11210 - Chinese Mahjong(暴力枚举)
- CodeForces - 863B Kayaking 暴力枚举
- 第三章 枚举、暴力
- CodeForces #431Div. 2 849B Tell your world 几何 暴力 枚举