博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CF 1003C Intense Heat【前缀和/精度/双层暴力枚举】
阅读量:6828 次
发布时间:2019-06-26

本文共 3845 字,大约阅读时间需要 12 分钟。

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 consecutive days. We have measured the temperatures during these n days; the temperature during i-th day equals 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 to day y, we calculate it as ∑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 k consecutive days. For example, if analyzing the measures [3,4,1,2] and k=3, we are interested in segments [3,4,1], [4,1,2] and [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?InputThe first line contains two integers n and k (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 integers a1, a2, ..., an (1≤ai≤5000) — the temperature measures during given n days.OutputPrint one real number — the heat intensity value, i. e., the maximum of average temperatures over all segments of not less than k consecutive days.Your answer will be considered correct if the following condition holds: |res−res0|<10−6, where res is your answer, and res0 is the answer given by the jury's solution.ExampleInput4 33 4 1 2Output2.666666666666667

【代码】:

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define debug() puts("++++")#define gcd(a,b) __gcd(a,b)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define fi first#define se second#define pb push_back#define sqr(x) ((x)*(x))#define ms(a,b) memset(a,b,sizeof(a))#define sz size()#define be begin()#define pu push_up#define pd push_down#define cl clear()#define lowbit(x) -x&x#define all 1,n,1#define rep(i,x,n) for(int i=(x); i<(n); i++)#define in freopen("in.in","r",stdin)#define out freopen("out.out","w",stdout)using namespace std;typedef long long ll;typedef unsigned long long ULL;typedef pair
P;const int INF = 0x3f3f3f3f;const ll LNF = 1e18;const int N = 1e5 + 20;const int maxm = 1e6 + 10;const double PI = acos(-1.0);const double eps = 1e-8;const int dx[] = {-1,1,0,0,1,1,-1,-1};const int dy[] = {0,0,1,-1,1,-1,1,-1};int dir[4][2] = { {0,1},{0,-1},{-1,0},{1,0}};const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};/*在有n个数的数列中,求max(所含元素至少k个的连续区间的平均值) *///之前至少看漏了,以为刚好k个,ri!!!int n,m;int a[N];int sum[N];int main(){ while(~scanf("%d%d",&n,&m)) { double Max=0; ms(sum,0); for(int i=1;i<=n;i++) { scanf("%d",&a[i]); sum[i] = sum[i-1] + a[i]; } for(int j=m; j<=n; j++) //枚举区间长度 { for(int i=1; i+j-1<=n; i++) { Max = max(Max,(double)(sum[i+j-1]-sum[i-1])*1.0/j); } } printf("%.10f\n",Max); }}/*8 70 1 2 3 4 53 4 1 2 5 9*/

转载于:https://www.cnblogs.com/Roni-i/p/9348514.html

你可能感兴趣的文章
col-md-*和col-sm-*
查看>>
前端开发大众手册(包括工具、网址、经验等)
查看>>
IOC容器
查看>>
“利益相关者”课堂讨论电子版
查看>>
意见总结
查看>>
servlet增删改查
查看>>
php - 中文字符串分割
查看>>
图解HTTP
查看>>
HTML - form (转)
查看>>
浅析C#深拷贝与浅拷贝 (转)
查看>>
3226. [SDOI2008]校门外的区间【线段树】
查看>>
如何解决jersey框架中以json格式返回数组,当数组中元素一个时json格式不对
查看>>
HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
查看>>
Kafka参数调优实战,看这篇文章就够了!
查看>>
delphi 把一个表的内容转到另一个表暂存时出错的解决方法。
查看>>
JavaScript 操作cookie
查看>>
BeanUtils.copyProperties() 用法
查看>>
微信公众平台开发 - 基础篇
查看>>
WinForm更新文件
查看>>
setprecision **fixed
查看>>