NUOJ 1242 Interference Signal (信号强度) (第八届河南省程序设计)
2016-05-28 18:32
357 查看
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
来源
第八届河南省程序设计大赛
题解:求至少m个连续的平均信号强度最大
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL shu[4200],he[4200];
int n,k,m;
int main()
{
scanf("%d",&k);
while (k--)
{
scanf("%d%d",&n,&m);
he[0]=0;
for (int i=1; i<=n; i++)
{
scanf("%lld",&shu[i]);
he[i]=he[i-1]+shu[i];///前1,2,3,4,---N的和
}
LL ma=0;
for (int i=m; i<=n; i++)
{
for (int j=0; j<=n-m&&i+j<=n; j++)
ma=max(ma,(he[j+i]-he[j])*1000/i);///至少m个的平均值最大
}
printf("%lld\n",ma);
}
return 0;
}
时间限制: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
来源
第八届河南省程序设计大赛
题解:求至少m个连续的平均信号强度最大
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define LL long long
LL shu[4200],he[4200];
int n,k,m;
int main()
{
scanf("%d",&k);
while (k--)
{
scanf("%d%d",&n,&m);
he[0]=0;
for (int i=1; i<=n; i++)
{
scanf("%lld",&shu[i]);
he[i]=he[i-1]+shu[i];///前1,2,3,4,---N的和
}
LL ma=0;
for (int i=m; i<=n; i++)
{
for (int j=0; j<=n-m&&i+j<=n; j++)
ma=max(ma,(he[j+i]-he[j])*1000/i);///至少m个的平均值最大
}
printf("%lld\n",ma);
}
return 0;
}
相关文章推荐
- JavaScript书单
- bootstrap中的dropdown组件改造click为hover
- 前端应当了解的Web缓存知识
- LaTeX技巧007:设置插入代码的样式
- html 中使用 sass
- Htmlayout早期的一个摸索作品
- JQuery实现shift键多选
- html strokeRect(20,20,150,100);
- 几种JS转跳页面方式
- jquery cookie记住用户名和密码(使用方法)
- angularjs对json数据的操作--收货地址列表
- jquery 中的框架
- javascript 工作必知(四) 类型转换
- 一个页面可以重复调用的TAB选项卡切换js代码 鼠标悬浮
- fastjson序列化hibernate查询的数据报错:failed to lazily initialize a collection of role
- dom中的事件
- jQuery+ASP.NET MVC基于CORS实现带cookie的跨域ajax请求
- bootstrap随笔记
- C#无需第三方插件实现json和table互转
- HTML5与CSS3学习笔记(二)