G.Interference Signal

Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 17 [Submit][Status][Web Board]

Description

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.

Input

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

Output

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

Sample Input

2
10 6
6
4
2
10
3
8
5
9
4
1
5 2
10
3
8
5
9

Sample Output

6500
7333

HINT

 

Source

第八届河南省赛

题解:让找长度大于等于M的连续子序列的最大平均值;

思路:简单dp,dp[i][j]=dp[i-1][j-1]+m[j];代表在j处前i个数的序列和;

然后判断找平均值;

代码:

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define SL(x) scanf("%lld",&x)
#define PI(x) printf("%d",x)
#define PL(x) printf("%lld",x)
#define P_ printf(" ")
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
typedef long long LL;
const int MAXN=2020;
int m[MAXN];
int dp[MAXN][MAXN];
double pp[MAXN][MAXN];
int main(){
int T,N,M;
SI(T);
while(T--){
SI(N);SI(M);
for(int i=1;i<=N;i++)SI(m[i]);
mem(dp,0);
for(int i=1;i<=N;i++){
for(int j=1;j<=N;j++){
dp[i][j]=dp[i-1][j-1]+m[j];
}
}
double x=0;
for(int i=M;i<=N;i++)
for(int j=M;j<=N;j++)
x=max(x,1.0*dp[i][j]/i);
printf("%d\n",(int)(1000*x));
}
return 0;
}

  

第八届河南省赛G.Interference Signal(dp)的更多相关文章

  1. 第八届河南省赛F.Distribution(水题)

    10411: F.Distribution Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 11  Solved: 8 [Submit][Status] ...

  2. 第八届河南省赛D.引水工程(kruthcra+prime)

    D.引水工程 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 118  Solved: 41 [Submit][Status][Web Board] D ...

  3. 第八届河南省赛C.最少换乘(最短路建图)

    C.最少换乘 Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 94  Solved: 25 [Submit][Status][Web Board] De ...

  4. 第八届河南省赛B.最大岛屿(dfs)

    B.最大岛屿 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 30  Solved: 18 [Submit][Status][Web Board] De ...

  5. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  6. POJ-2421Constructing Roads,又是最小生成树,和第八届河南省赛的引水工程惊人的相似,并查集与最小生成树的灵活与能用,水过~~~

    Constructing Roads Time Limit: 2000MS   Memory Limit: 65536K               Description There are N v ...

  7. 第六届河南省赛 River Crossing 简单DP

    1488: River Crossing Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 83  Solved: 42 SubmitStatusWeb ...

  8. Little Sub and Piggybank (杭师大第十二届校赛G题) DP

    题目传送门 题意:每天能往存钱罐加任意实数的钱,每天不能多于起那一天放的钱数.如果某一天的钱数恰好等于那天的特价商品,则可以买,求最后的最大快乐值. 思路:先来一段来自出题人的题解: 显然的贪心:如果 ...

  9. G.Interference Signal---河南省第八届程序设计大赛(dp)

    G.Interference Signal 时间限制: 2 Sec  内存限制: 128 MB提交: 47  解决: 18[提交][状态] 题目描述 Dr.Kong’s laboratory moni ...

随机推荐

  1. MVC 4 结合jquery.uploadify 上传实例

    前言:由于今天公司源代码服务瘫痪,没法编写代码,利用这个有限的时间,做了一个小小的 基于MVC的图片上传demo,貌似近些年来MVC十分火爆,相关的demo也数不胜数,小弟就在这里打着MVC的旗子,狐 ...

  2. TF卡速度测试对比 Class数越高速度越快

    存储卡(TF卡)是手机扩展存储的大杀器,让你多装n部学习资料,多装n个外语听力练习.除了装东西外,存储卡性能不佳也会影响手机的整体性能以及体验的.本文主要针对Android手机,我是懒人,但我讨厌懒人 ...

  3. 【译】浅谈微软OneNote的自动化测试工具

    当我们向人们介绍OneNote的自动化时,有一个问题被相当频繁地提到,担忧我们的自动化框架中UI层面测试偏少. 我不喜欢基于UI的自动化.我知道在市场上有许多的自动化系统都是基于UI的自动化(点击按钮 ...

  4. poj 3273 Monthly Expense (二分搜索,最小化最大值)

    题目:http://poj.org/problem?id=3273 思路:通过定义一个函数bool can(int mid):=划分后最大段和小于等于mid(即划分后所有段和都小于等于mid) 这样我 ...

  5. docker 数据映射方案

    docker run -itd -v /data/:/data1 centos bash // -v 用来指定挂载目录, :前面的/data为本地目录,:后面的/data1 为容器里的目录: dock ...

  6. ntpd和ntpdate的区别

    之前配置ntpd的时候搜到一句话,印象很深刻,也觉得很有标题党的效果,就借鉴为标题了:“我认为有几种人是必须不招聘/裁掉的: 1 用ntpdate代替ntpd的人”但具体原因不太懂,总觉得还是用ntp ...

  7. C# MVC 自学笔记—6 编辑方法和编辑视图

    ==============================翻译============================== 运行该应用程序并浏览到Movies控制器通过将/Movies追加到您的浏览 ...

  8. 移动开发之fastclick 点击穿透

    穿透(点穿)是在mobile各种浏览器上发生的常见的bug.可能是由click事件的延迟(300ms)或者事件冒泡导致 现象:在A页面中有个 btn1<或a标签>,在B页面中有个 btn2 ...

  9. 投资学第一章 investments-introduction

    转载请注明来自souldak,微博:@evagle 砖搬多了有点累,今天学学投资学. 这章主要是一些重要的概念.   real assets / financial assets , fixed-in ...

  10. swift论坛正式上线

    www.iswifting.com swift论坛正式上线.有问答专区,也有技术分享区,还有学习资料区,大家一起学习成长! 2014中国互联网大会于8月26日开幕. 政府主管部门.行业专家.企业领袖将 ...