第八届河南省程序设计大赛-NYOJ-1242-Interference Signal(水题)
2016-03-14 13:55
381 查看
Interference Signal
时间限制:2000 ms | 内存限制:65535 KB
难度:1
描述
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
来源
第八届河南省程序设计大赛
题意:第一行输入K,代表有K组输入数据,接下来输入N,M;N代表有N个数据将要输入,M表示求平均数时,最少要求M个数的平均数,接下来输入N个数据。
输出最大的平均数。
没考什么算法,考的都是循环控制和输出控制,都是最基本的语法,题解依旧略过去吧
代码
或许这题最难的就是翻译题意。。。。。
时间限制:2000 ms | 内存限制:65535 KB
难度:1
描述
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
来源
第八届河南省程序设计大赛
题意:第一行输入K,代表有K组输入数据,接下来输入N,M;N代表有N个数据将要输入,M表示求平均数时,最少要求M个数的平均数,接下来输入N个数据。
输出最大的平均数。
没考什么算法,考的都是循环控制和输出控制,都是最基本的语法,题解依旧略过去吧
代码
#include<stdio.h> #include<string.h> #include<string> #include<stack> #include<queue> #include<math.h> #include<limits.h> #include<iostream> #include<algorithm> using namespace std; //省赛水题 int main() { int K; cin>>K; while(K--) { int n,m; scanf("%d%d",&n,&m); int num[2005];//接收数据 for(int i=0; i<n; i++) cin>>num[i]; double maxn=0.0; for(int i=0; i+m<=n; i++)//外层循环控制起始位置 { for(int k=m; k<=n&&i+k<=n; k++)//中层循环保证求和区间 { double sum=0.0; for(int j=0; j<k; j++)//内层循环求和 sum+=num[i+j]; maxn=max(sum/k,maxn);//求和后保留较大的平均数 } } printf("%d\n",(int)(maxn*1000)); } }
或许这题最难的就是翻译题意。。。。。
相关文章推荐
- javascript window.name是什么?
- 前端分页效果
- JavaScript实现360度全景图片展示效果
- web前端之路 第一个脚印
- jquery插件的编写
- jquery元素插入、删除、清空
- js日期格式化
- HTML网页超链接title赋一个变量
- JavaScript生成八位随机数(含数字、字母、特殊符号)
- IE8以下的attachEvent()和其他浏览器的addEventListener()区别
- W3C Blog: HTML-下一步是什么?
- JSON
- 【Egret】Lakeshore 使用中的一些疑难解决技巧!
- maven 3.3.9编译spark1.5.0 cdh5.5.1
- 用jquery追加的元素不能触发treeview事件
- 为什么直接访问项目名与加上index.html看到的页面不一样
- 导入外部css文件时link和@import的区别
- JSP 中文问题完全解决方案
- .net MVC4 web Api输出Json格式实例
- JS第十二天