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. tiny4412学习笔记-将uboot、zImage、文件系统烧到emmc中

    1.首先还是要将u-boot写入SD卡中从SD卡启动. 使用读卡器将SD插入电脑中,使用umount卸载u盘, fdisk -l显示其挂载点为 /dev/sdb1 切换到/home/bunfly/im ...

  2. 15.java.lang.InstantiationException

    java.lang.InstantiationException 实例化异常 当试图通过Class的newInstance()方法创建某个类的实例,但程序无法通过该构造器来创建该对象时引发 Class ...

  3. CSS转载

    原文地址:http://www.cnblogs.com/dolphinX/archive/2012/10/13/2722501.html 页面布局,或者是在页面上做些小效果的时候经常会用到 displ ...

  4. [置顶] 请听一个故事------>你真的认为iPhone只是一部手机?苹果惊天秘密!!

    在网上看到的一篇小说,感觉有点意思,转载过来大家一起围观下,作者很幽默很风趣. 导读:iPhone的隐藏功能!Jobs的军方身份!图灵服毒自杀的传奇故事!中兴华为的神秘背景! 你真的认为iPhone只 ...

  5. 得到client真IP住址

    1.引进的必要性log4j-1.2.14.jar package org.ydd.test; import java.util.Enumeration; import javax.servlet.ht ...

  6. Web安全測试二步走

    Web安全測试时一个比較复杂的过程,软件測试人员能够在当中做一些简单的測试,例如以下: Web安全測试也应该遵循尽早測试的原则,在进行功能測试的时候(就应该运行以下的測试Checklist安全測试场景 ...

  7. C#实现发送和接收pop3邮件方法

    必须引入Interop.jmail.dll应用 /// <summary>    /// 收取新邮件.不删除老邮件.收取邮件后写入数据库    /// </summary>   ...

  8. SQL练习之不反复执行相同的计算

    下面是Demo所需要的代码: CREATE TABLE Fee ( Income ,), overhead ,) ) ,) ,) ,) ,) ,) ,) 现在有一个报表系统,需要根据Fee表获得以下数 ...

  9. JavaScript之Ajax

    简介:AJax是在2005年被Adaptive Path的Jesse James Garrett发明的,用户概括异步加载页面内容的技术---说通俗点,Ajax就是实现局部页面通过JavaScript与 ...

  10. matlab GUI之常用对话框(二)-- 进度条的使用方法

    常用对话框(二) 进度条   waitbar 调用格式: h = waitbar(x,'message')  waitbar(x,'message','CreateCancelBtn','button ...