当前位置:网站首页>关于一个神奇函数的用法
关于一个神奇函数的用法
2022-07-01 18:53:00 【Aidan 347】
题目描述
给定一个长度为n的序列a_i,定义a[i]为第i个元素的价值。现在需要找出序列中最有价值的“段落”。段落的定义是长度在[S,T]之间的连续序列。最有价值段落是指平均值最大的段落,
段落的平均值=段落总价值/段落长度。
输入输出格式
输入格式:
第一行一个整数n,表示序列长度。
第二行两个整数S和T,表示段落长度的范围,在[S,T]之间。
第三行到第n+2行,每行一个整数表示每个元素的价值指数。
输出格式:
一个实数,保留3位小数,表示最优段落的平均值。
输入输出样例
输入样例#1:
3
2 2
3
-1
2
输出样例#1:
1.000
说明
【数据范围】
对于30%的数据有n<=1000。
对于100%的数据有n<=100000,1<=S<=T<=n,-10000<=价值指数<=10000。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1e5+10;
int n,s,t;
int a[N];
double res;
int main()
{
scanf("%d", &n);
scanf("%d%d", &s, &t);
for(int i=1;i<=n;i++) scanf("%d", &a[i]);
for(int i=1;i<=n;i++) a[i]+=a[i-1];
for(int i=s;i<=t&&(double)clock() / CLOCKS_PER_SEC <= 0.95;i++)
{
for(int j=1;j+i-1<=n;j++)
{
int r = j+i-1;
double sum = a[r] - a[j-1];
res = max(res, (double)(sum*1.0/i));
}
}
printf("%.3lf",res);
return 0;
}下面这段代码可以保证循环进行了0.95s之后自动退出循环。。。
(double)clock() / CLOCKS_PER_SEC <= 0.95
边栏推荐
- 再回顾集合容器
- Tensorflow reports an error, could not load dynamic library 'libcudnn so. eight
- New window open page -window open
- Oracle physical architecture
- Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
- list分割成满足和不满足条件的集合(partitioningBy)
- HLS4ML/vivado HLS 报错解决方案
- Optimization of video streaming with repeated requests in the case of unstable easygbs network
- 3D全景模型展示可视化技术演示
- Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
猜你喜欢
随机推荐
[research data] observation on the differences of health preservation concepts among people in 2022 - Download attached
独家消息:阿里云悄然推出RPA云电脑,已与多家RPA厂商开放合作
The large list set is divided into multiple small list sets in equal proportion
JVM内存模型
HLS4ML进入方法
JS 之 常用内置类的使用
switch 有四样写法你知道么
对金额进行求和
[research materials] iResearch tide Watching: seven major trends in the clothing industry - Download attached
Understand the structure in C language in one article
新窗口打开页面-window.open
开发那些事儿:EasyCVR平台添加播放地址鉴权功能
servlet知识点
2022/5/23-2022/5/30
Wechat applet realizes keyword highlighting
list大集合等比分割成多个小list集合
Powerful, easy-to-use, professional editor / notebook software suitable for programmers / software developers, comprehensive evaluation and comprehensive recommendation
docker ubuntu容器中安装mysql遇到的问题
上大学后明白了哪些坑人的事?
Getting started with fastdfs







![P2433 [deep foundation 1-2] primary school mathematics n in one](/img/28/e5eab8927694ea002b536202a1b5ea.png)
