『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号了,突然加进去也就上一天然后排位赛了,没学什么就去打怕是要被虐成渣,今天开学前一天,看到最后有一场大的排位赛,就上去试 ...
随机推荐
- JavaWeb中Servlet和JSP的分工案例
jsp和Servlet的分工: * JSP: > 作为请求发起页面,例如显示表单.超链接. > 作为请求结束页面,例如显示数据. * Servlet: &g ...
- C# CRC16算法实现【转】
/// <summary> /// CRC校验 /// </summary> public class CRC { #region CRC16 public static by ...
- 【转】C# GDAL 配置
共生成9个dll,如下图: 1.在程序中添加*_csharp.dll四个文件的引用: 2.将剩余的五个文件复制到程序的Debug文件夹中:(如果不复制这五个文件就会出现类似“OSGeo.GDAL.Gd ...
- vue2.0中的ref.html
前置知识请戳这里 获取DOM对象以及组件对象 <!DOCTYPE html> <html> <head> <meta charset="UTF-8& ...
- myeclipse 下载 checkstyle 引入后不显示问题
参照这篇博客,http://blog.csdn.net/zzq900503/article/details/42003499 下载最新的checkstyle版本后,在本地导入后一直不显示,步骤什么的也 ...
- JDBC URL格式定制
数据库URL制定: 当加载的驱动程序,可以建立程序中使用DriverManager.getConnection()方法的连接.为方便参考,让列出了三个重载DriverManager.getConnec ...
- 深入理解mysql的底层实现
MySQL 的常用引擎 1. InnoDB InnoDB 的存储文件有两个,后缀名分别是 .frm 和 .idb,其中 .frm 是表的定义文件,而 idb 是数据文件. InnoDB 中存在表锁和行 ...
- ORACLE 角色授权
直接例子: 1.CREATE USER 用户名 identified by 密码 default tablespace 表空间名;GRANT CONNECT TO 用户名; GRANT RESOURC ...
- java代码修改了之后运行仍然是原程序
有的时候java代码改了之后但是运行的程序却没有发生改动,这是什么情况呢?可能懂得的人都觉得十分简单,但对于我这样的小白来说确实很费力.java代码更改后需要编译生成.class文件,说的直白点,这个 ...
- Python学习---重点模块之logging
日志级别 日志级别 critical > error > warning > info > debug, 默认是从warning开始打印 import logging # 日 ...