当前位置:网站首页>关于一个神奇函数的用法
关于一个神奇函数的用法
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
边栏推荐
猜你喜欢

Detailed configuration of network security "Splunk" in national vocational college skills competition

Review the collection container again

GC垃圾回收

Interview questions shared in today's group

全国职业院校技能大赛网络安全“splunk“详细配置

自定义插入页面标签以及实现类似通讯录的首字母搜索

Bind this of the current scope for callback functions in other cases such as timers and delayers

Example explanation: move graph explorer to jupyterlab

1592 example 1 King (sgu223 loj10170 luogu1896 increase + / provincial election -) violent thinking pressure DP 01 Backpack

STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
随机推荐
ORA-01950
DS transunet: Dual Swing transformer u-net for medical image segmentation
Use of common built-in classes of JS
JVM memory model
PHP获取微信小程序和小程序商店外链地址
Anaconda installs the virtual environment to the specified path
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
【无标题】
List is divided into sets that meet and do not meet conditions (partitioningby)
一文读懂C语言中的结构体
Technology T3 domestic platform! Successfully equipped with "Yihui domestic real-time system sylixos"
Getting started with fastdfs
Stack Overflow 2022 开发者调查:行业走向何方?
JS proxy
Object creation
Arduino Stepper库驱动28BYJ-48步进电机测试程序
CMU AI PhD first year summary
C#聯合halcon應用——大華相機采集類
C # joint halcon Application - Dahua Camera Collection class
Define dichotomy lookup