当前位置:网站首页>关于一个神奇函数的用法
关于一个神奇函数的用法
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
边栏推荐
- 2022/6/8-2022/6/12
- February 15, 2022: sweeping robot. There is a floor sweeping robot in the room (represented by a grid). Each grid in the grid has two possibilities: empty and obstacles. The sweeping robot provides fo
- Review the collection container again
- 基于图的 Affinity Propagation 聚类计算公式详解和代码示例
- Hls4ml/vivado HLS error reporting solution
- Win11暂停更新点不了怎么办?Win11暂停更新是灰色的如何解决?
- Linux下安装Redis,并配置环境
- Hls4ml reports an error the board_ part definition was not found for tul. com. tw:pynq-z2:part0:1.0.
- Install redis under Linux and configure the environment
- Using win7 vulnerability to crack the system login password
猜你喜欢
随机推荐
Time series analysis using kibana timelion
qobject_cast用法
Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
windows环境 redis安装和启动(后台启动)
Optimization of video streaming with repeated requests in the case of unstable easygbs network
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
C # joint Halcon application - Dahua camera acquisition class
Anaconda installs the virtual environment to the specified path
How to use console Log print text?
Use of common built-in classes of JS
DS transunet: Dual Swing transformer u-net for medical image segmentation
list大集合等比分割成多个小list集合
C#聯合halcon應用——大華相機采集類
全国职业院校技能大赛网络安全“splunk“详细配置
Test self-study people must see: how to find test items in software testing?
【蓝桥杯Web】2022年第十三届蓝桥杯Web大学组国赛真题解析
JDBC中如何添加事务
Procédure de mesure du capteur d'accord vibrant par le module d'acquisition d'accord vibrant
tensorflow报错Could not load dynamic library ‘libcudnn.so.8
GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速