nyoj 1242 Interference Signal 第八届河南省程序设计大赛
2016-05-30 09:18
323 查看
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
来源第八届河南省程序设计大赛
#include<stdio.h> int num[2005]; int main() { int k,n,m; int i,j; long long sum; scanf("%d",&k); while(k--) { scanf("%d %d",&n,&m); for(i=0;i<n;i++) { scanf("%d",&num[i]); } int h=n-m+1; long long c,ave=-1; while(h--) { for(i=0;i<(n-m+1);i++) { sum=0; for(j=i;j<m+i;j++) { sum+=num[j]; } //printf(" sum %lld\n",sum); c=sum*1000/(m*1.0); if(ave<c) ave=c; } m+=1; } printf("%lld\n",ave); } return 0; }
相关文章推荐
- jquery获取表单数据
- Loadrunner:LR提交JSON格式的POST请求
- json在线解析(去空格并转义), utf-8在线转码, ip归属地查询
- 浅析Javascript中bind()方法的使用与实现
- javascript 减少全部变量
- CSS3 Transform 【3D 】
- Bootstrap Paginator分页插件使用方法详解
- 深入理解JavaScript中的call、apply、bind方法的区别
- HTML中字体单位px pt em之间的转换
- React Native之底层源码分析篇
- 全面解析Bootstrap中transition、affix的使用方法
- jsp的简单总结(一)
- 全面解析Bootstrap中form、navbar的使用方法
- jstorm简介(转)
- 脉象feature
- html5-video标签屏蔽右键视频另存为的js代码
- CSS3 perspective 属性
- JQuery在开发里面的使用
- [leetcode] 237. Delete Node in a Linked List
- 一个js爬虫