CF1003C Intense Heat递推

2024-02-19 14:38
文章标签 递推 intense heat cf1003c

本文主要是介绍CF1003C Intense Heat递推,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

  

题目描述

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 n n n consecutive days. We have measured the temperatures during these n n n days; the temperature during i i i -th day equals ai a_i ai​ .

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 x x x to day y y y , we calculate it as ∑i=xyaiy−x+1 \frac{\sum \limits_{i = x}^{y} a_i}{y - x + 1} y−x+1i=x∑y​ai​​ (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 k k k consecutive days. For example, if analyzing the measures [3,4,1,2] [3, 4, 1, 2] [3,4,1,2] and k=3 k = 3 k=3 , we are interested in segments [3,4,1] [3, 4, 1] [3,4,1] , [4,1,2] [4, 1, 2] [4,1,2] and [3,4,1,2] [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?

输入输出格式

输入格式:

 

The first line contains two integers n n n and k k k ( 1≤k≤n≤5000 1 \le k \le n \le 5000 1≤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 n n n integers a1 a_1 a1​ , a2 a_2 a2​ , ..., an a_n an​ ( 1≤ai≤5000 1 \le a_i \le 5000 1≤ai​≤5000 ) — the temperature measures during given n n n days.

 

输出格式:

 

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

Your answer will be considered correct if the following condition holds: ∣res−res0∣<10−6 |res - res_0| < 10^{-6} ∣res−res0​∣<10−6 , where res res res is your answer, and res0 res_0 res0​ is the answer given by the jury's solution.

 

输入输出样例

输入样例#1: 复制

4 3
3 4 1 2

输出样例#1: 复制

2.666666666666667

题意:在数列大于等于k长度的连续区间内,求最大平均值

思路:通过sum【】算出从开始到每一个数(包括)的和,然后区间内的和为sun[j]-sun[i-j-1],通过循环求出最大平均值

#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long int a[5008],sum[5008];
int main()
{int n,lenth;double max_ave=0;scanf("%d%d",&n,&lenth);for(int i=1;i<=n;i++){scanf("%lld",&a[i]);}sum[0]=0;for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];for(int j=lenth;j<=n;j++){for(int i=1;i+j<=n+1;i++){max_ave=max(max_ave,double(sum[i+j-1]-sum[i-1])/j);}}printf("%.15lf",max_ave);return 0;}

 

这篇关于CF1003C Intense Heat递推的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/724979

相关文章

uva 568 Just the Facts(n!打表递推)

题意是求n!的末尾第一个不为0的数字。 不用大数,特别的处理。 代码: #include <stdio.h>const int maxn = 10000 + 1;int f[maxn];int main(){#ifdef LOCALfreopen("in.txt", "r", stdin);#endif // LOCALf[0] = 1;for (int i = 1; i <=

OpenStack离线Train版安装系列—10.控制节点-Heat服务组件

本系列文章包含从OpenStack离线源制作到完成OpenStack安装的全部过程。 在本系列教程中使用的OpenStack的安装版本为第20个版本Train(简称T版本),2020年5月13日,OpenStack社区发布了第21个版本Ussuri(简称U版本)。 OpenStack部署系列文章 OpenStack Victoria版 安装部署系列教程 OpenStack Ussuri版

HLJUOJ1128 HDU2046(数学递推)

1128: 递推求解专题练习三 Time Limit: 1 Sec   Memory Limit: 128 MB Submit: 8   Solved: 6 [ Submit][ Status][ Web Board] Description 在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数。 例如n=3时,为2× 3方格,骨牌的铺放方案有三

【递推】【DP】-HDU-2064-汉诺塔③

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2064 题目描述:从最左边移到最右边柱子的过程中必须经过中间柱子。 解题思路: 进ACM组时候的考试题,当时虐我的题终于被我虐回来了。。一眼看出方程,1A了。。。呵呵。。满足一下我的虚荣心,,,抚慰一下受挫的心灵吧。 AC代码: #include <iostream>using names

【递推】【DP】-HDU-1996-汉诺塔⑥

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1996 题目描述:问三个柱子上放N个盘子,一共可能有多少种组合?(可以有柱子不放,放的时候依然满足下面盘子比上面盘子大) 解题思路: 对于放N个盘子,ans [ N ] = 3 + 6 * f ( N ) +6 * g ( N ) 这三项依次代表这N个盘子分成一堆,两堆,三堆时有多少种可能。排列

【递推】【DP】-HDU-1995-汉诺塔⑤

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1995 题目描述:计算汉诺塔中某个盘子的移动次数 解题思路: 想了好久,突然顿悟! 思路如下,所谓递推,即是前者与后者存在直接联系,由前者可以直接推出后者,因此必须有一端是已知的,这题里显然最下面的盘子只被动了一次,这就是开端,然后我们考虑紧挨着的两张盘子的递推关系,发现上面盘子是紧挨着的下面盘

【递推】【DP】-HDU-1207-汉诺塔②

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1207 题目描述:四柱汉诺塔 解题思路: 开始想了方程 f [ n ] = 2 * f [n - 2] + 3和 f [ n ] = 2 * f [n - 3] + 7。结果都不对,很郁闷,纠结半天之后,上网查攻略去了,啊!我就差一点了,但也是差了最为关键的一步! 正确的方程应该是: f [

蓝桥杯备赛day02:递推

斐波那契数列 #include <bits/stdc++.h>using namespace std;int main(){int n;cin>>n;int dp[n+1];dp[1]=1;dp[2]=1;for(int i = 3;i <= n;i++) dp[i] = dp[i-1]+dp[i-2];cout<<dp[n];return 0;} n = int(input())

递推—杭电2044 一只小蜜蜂...

http://acm.hdu.edu.cn/showproblem.php?pid=2044 一只小蜜蜂... Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 35811    Accepted Submission(s): 1317

数位dp n内1的个数递推找规律

1061:数字统计 查看提交统计提问 总时间限制:  1000ms  内存限制:  10000kB 描述 给出一个整数n(1<=n<=20000000),要求输出从1到n间所有数字中“1”的出现次数.例如:数字11,1到11间数字“1”的出现次数为4。(1,10,11,11出现4次,因为11有两个1,所以出现4次) 输入 一个整数n,(1<=n<=20000000)