今日兴趣新闻:

NASA 研制最强推进器,加速度可达每秒 40 公里,飞火星全靠它

链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7B"nid"%3A"news_11707429683828231737"%7D&n_type=0&p_from=1

------------------------------------------------题目----------------------------------------------------------

The heat during the last few days has been really intense. Scientists from all over the Berland study how the temperatures and weather change, and they claim that this summer is abnormally hot. But any scientific claim sounds a lot more reasonable if there are some numbers involved, so they have decided to actually calculate some value which would represent how high the temperatures are.

Mathematicians of Berland State University came up with a special heat intensity value. This value is calculated as follows:

Suppose we want to analyze the segment of nn consecutive days. We have measured the temperatures during these nn days; the temperature during ii-th day equals aiai.

We denote the average temperature of a segment of some consecutive days as the arithmetic mean of the temperature measures during this segment of days. So, if we want to analyze the average temperature from day xx to day yy, we calculate it as ∑i=xyaiy−x+1∑i=xyaiy−x+1 (note that division is performed without any rounding). The heat intensity value is the maximum of average temperatures over all segments of not less than kkconsecutive days. For example, if analyzing the measures [3,4,1,2][3,4,1,2] and k=3k=3, we are interested in segments [3,4,1][3,4,1], [4,1,2][4,1,2] and [3,4,1,2][3,4,1,2] (we want to find the maximum value of average temperature over these segments).

You have been hired by Berland State University to write a program that would compute the heat intensity value of a given period of days. Are you up to this task?

Input

The first line contains two integers nn and kk (1≤k≤n≤50001≤k≤n≤5000) — the number of days in the given period, and the minimum number of days in a segment we consider when calculating heat intensity value, respectively.

The second line contains nn integers a1a1, a2a2, ..., anan (1≤ai≤50001≤ai≤5000) — the temperature measures during given nn days.

Output

Print one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than kkconsecutive days.

Your answer will be considered correct if the following condition holds: |res−res0|<10−6|res−res0|<10−6, where resres is your answer, and res0res0 is the answer given by the jury's solution.

input

   

output

2.666666666666667

------------------------------------------------题目----------------------------------------------------------

(一) 题目分析:

    正常div3难度题型,难度处理可能是在求和统计上,题目大概含义就是:

    求n个数中至少连续k个数的平均值的最大值,如:n=4,k=3   给定的n个数是3 4 1 2,则求[3,4,1],[4,1,2],[3,4,1,2]三个区间的平均值的最大值。

    我用的方法比较简单,就是简单的取值求和,今天下午打完题之后这道题还特地搜了一下,发现还有其他的解法:前缀和 /  尺缩

(二)AC代码:

    因为代码比较简单,依旧不分块了~

#include<stdio.h>
#define max(a,b) (a>b) ? a : b
using namespace std;
int n,k,sum;
int temp[];
double ans,all;
int main()
{
scanf("%d%d",&n,&k);
ans = ;
for(int i = ;i<=n;i++) scanf("%d",&temp[i]); for(int i = ;i<=n;++i)
{
sum = ;
for(int j = i;j<=n;++j)
{
sum+= temp[j];
if (j - i + >= k)
{
all = sum * 1.0 / (j - i + );
if(all>ans) ans = all;
}
}
}
printf("%.15f\n",ans);
return ;
}

(三)AC截图:

(四)解后分析:

  贡献一个队内牛逼师兄高效率的代码:

  备注一下:前缀和

『ACM C++』 Codeforces | 1003C - Intense Heat的更多相关文章

  1. 『ACM C++』 Codeforces | 1066A - Points in Segments

    大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...

  2. 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3

    今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...

  3. 『ACM C++』 Codeforces | 1066B - Heaters

    今日不写日感,直接扔上今日兴趣点: 新研究称火星曾经有一个巨大的地下水系统 链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7 ...

  4. CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】

    The heat during the last few days has been really intense. Scientists from all over the Berland stud ...

  5. 『ACM C++』 PTA 天梯赛练习集L1 | 007-011

    真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...

  6. 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)

    呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...

  7. 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)

    今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...

  8. 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)

    今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...

  9. 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester

    这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...

随机推荐

  1. push本地代码到github发生错误的解决办法

    有一天,我在github上编写好了README.md这个文件,接着发现本地有段代码忘记上传了,于是熟练的输入git add .   git commit -m "modify",以 ...

  2. 用虚拟信用卡注册Google Play开发者账号

    本文首发于http://www.abcdsxg.cn/free/net/562 虚拟信用卡 首先介绍一下虚拟信用卡(Virtual Credit Card),顾名思义,虚拟就是没有实体卡,一般都是在提 ...

  3. Java—IO流 对象的序列化和反序列化

    序列化的基本操作 1.对象序列化,就是将Object转换成byte序列,反之叫对象的反序列化. 2.序列化流(ObjectOutputStream),writeObject 方法用于将对象写入输出流中 ...

  4. javascript面向对象的写法03

    javascript面向对象的写法03 js一些基础知识的说明 prototype 首先每个js函数(类)都有一个prototype的属性,函数是类.注意类有prototype,而普通对象没有. js ...

  5. C#接收WebSphere MQ中文乱码问题

    最近在用IBM的WebSphere MQ做数据传输,客户端操作系统Windows,服务器是AIX,我们用的都是UTF-8编码,但是联调时发现带中文的都出现了乱码.折腾了好久才发现问题,原来是CCSID ...

  6. C++ virtual inheritance ZZ

       虚继承 是面向对象编程中的一种技术,是指一个指定的基类,在继承体系结构中,将其成员数据实例共享给也从这个基类型直接或间接派生的其它类. 举例来说:假如类A和类B各自从类X派生(非虚继承且假设类X ...

  7. C# 操作Excel 格式

    数字(Range.NumberFormatlocal 属性)常规:Range.NumberFormatlocal = "G/通用格式"数值:Range.NumberFormatlo ...

  8. Struts2学习-ssh框架

    SSH是 struts+spring+hibernate的一个集成框架,是目前比较流行的一种Web应用程序开源框架. http://www.cnblogs.com/laibin/p/5847111.h ...

  9. html5shiv.js和respond.js引入不起作用解决

    当项目需求需要兼容ie7,8这些奇葩浏览器时,考虑到h5的便捷性及响应式,我们往往引入html5shiv.js和respond.js来让ie7,8兼容h5及一些响应式变化,引入时就需要用到条件注释,原 ...

  10. posix进程间的通信

    1.无名管道 1.1管道是Linux支持的最初Unix IPC形式之一,具有以下特点: 管道是半双工的,数据只能向一个方向流动:需要双方通信时,需要建立起两个管道: 只能用于父子进程或者兄弟进程之间( ...