『ACM C++』 Codeforces | 1003C - Intense Heat
今日兴趣新闻:
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的更多相关文章
- 『ACM C++』 Codeforces | 1066A - Points in Segments
大一生活真 特么 ”丰富多彩“ ,多彩到我要忙到哭泣,身为班长,很多班级的事情需要管理,也是,什么东西都得体验学一学,从学生会主席.团委团总支.社团社长都体验过一番了,现在差个班长也没试过,就来体验了 ...
- 『ACM C++』 Codeforces | 1005D - Polycarp and Div 3
今天佛了,魔鬼周一,在线教学,有点小累,但还好,今天AC了一道,每日一道,还好达成目标,还以为今天完不成了,最近任务越来越多,如何高效完成该好好思考一下了~最重要的还是学业的复习和预习. 今日兴趣新闻 ...
- 『ACM C++』 Codeforces | 1066B - Heaters
今日不写日感,直接扔上今日兴趣点: 新研究称火星曾经有一个巨大的地下水系统 链接:https://mbd.baidu.com/newspage/data/landingsuper?context=%7 ...
- CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
The heat during the last few days has been really intense. Scientists from all over the Berland stud ...
- 『ACM C++』 PTA 天梯赛练习集L1 | 007-011
真的是忙头晕了,学业.ACM打题.班级活动.自学新东西,哇这充实的大学~ ------------------------------------------------L1-007--------- ...
- 『ACM C++』HDU杭电OJ | 1418 - 抱歉 (拓扑学:多面体欧拉定理引申)
呕,大一下学期的第一周结束啦,一周过的挺快也挺多出乎意料的事情的~ 随之而来各种各样的任务也来了,嘛毕竟是大学嘛,有点上进心的人多多少少都会接到不少任务的,忙也正常啦~端正心态 开心面对就好啦~ 今天 ...
- 『ACM C++』HDU杭电OJ | 1425 - sort (排序函数的特殊应用)
今天真的是累哭了,周一课从早八点半一直上到晚九点半,整个人要虚脱的感觉,因为时间不太够鸭所以就回头看看找了一些比较有知识点的题来总结总结分析一下,明天有空了就开始继续打题,嘻嘻嘻. 今日兴趣电影: & ...
- 『ACM C++』HDU杭电OJ | 1415 - Jugs (灌水定理引申)
今天总算开学了,当了班长就是麻烦,明明自己没买书却要带着一波人去领书,那能怎么办呢,只能说我善人心肠哈哈哈,不过我脑子里突然浮起一个念头,大二还要不要继续当这个班委呢,既然已经体验过就可以适当放下了吧 ...
- 『ACM C++』Virtual Judge | 两道基础题 - The Architect Omar && Malek and Summer Semester
这几天一直在宿舍跑PY模型,学校的ACM寒假集训我也没去成,来学校的时候已经18号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
随机推荐
- ASP.NET内容页中访问母版页中的对象
在ASP.NET2.0开始,提供了母版页的功能.母版页由一个母版页和多个内容页构成.母版页的主要功能是为ASP.NET应用程序中的页面创建相同的布局和界面风格.母版页的使用与普通页面类似,可以在其中放 ...
- 爬虫入门之Scrapy框架基础rule与LinkExtractors(十一)
1 parse()方法的工作机制: 1. 因为使用的yield,而不是return.parse函数将会被当做一个生成器使用.scrapy会逐一获取parse方法中生成的结果,并判断该结果是一个什么样的 ...
- windows下安装配置RabbitMQ
安装部署 1.当前环境以及参考资料出处 部署环境:windows server 2008 r2 enterprise 官方安装部署文档:http://www.rabbitmq.com/install- ...
- 【SQL重温】面试之数据库基础练习
简介 最近在练习SQL基础,首先感叹一下,在机器上写和在纸上写还是有区别的. 本文的练习题目请点击此链接进行查看:http://www.cnblogs.com/edisonchou/p/3878135 ...
- .net 面向对象程序设计深入](2)UML
1.用例图简介 定义:用例图主要用来描述“用户.需求.系统功能单元”之间的关系.它展示了一个外部用户能够观察到的系统功能模型图. 类型:动态图 应用:需求分析阶段 2.用例图元素 2.1 参与者(Ac ...
- Vim快捷输出查找寄存器的内容(去除\<,\>和\V)
Vim自带的*搜索会自动在单词两头加上\<和\>,使用第三方的vnoremap *,则是加上前缀\V, 当我们想要输出刚刚搜索的内容时可用<C-r>/,但是很可能会带上多余的符 ...
- less 学习
收藏地址 : http://www.bootcss.com/p/lesscss/
- 表空间常用sql汇总
表空间碎片相关:select tablespace_name, round(sqrt(max(blocks) / sum(blocks)) * (100 / sqr ...
- January 25 2017 Week 4 Wednesday
In every triumph, there's a lot of try. 每个胜利背后都有许多尝试. There's a lot of try behind every success, and ...
- 全国大学生数据挖掘邀请赛中的NDCG
转:http://www.zhizhihu.com/html/y2011/2794.html 评价标准 性能良好的评分模型,应该能够给予那些引起msg或click的候选会员更高的评分(排序靠前),从而 ...