当前位置:网站首页>On the usage of a magic function
On the usage of a magic function
2022-07-01 20:05:00 【Aidan 347】
Title Description
Given a length of n Sequence a_i, Definition a[i] For the first time i The value of two elements . Now we need to find the most valuable in the sequence “ The paragraph ”. A paragraph is defined as having a length of [S,T] A continuous sequence between . The most valuable paragraph refers to the paragraph with the highest average value ,
Average of paragraphs = Total paragraph value / Paragraph length .
I / O format
Input format :
The first line is an integer n, Represents sequence length .
The second line is two integers S and T, Indicates the range of paragraph length , stay [S,T] Between .
Third line to third line n+2 That's ok , An integer in each line represents the value index of each element .
Output format :
A real number , Retain 3 Decimal place , Represents the average value of the best paragraph .
I/o sample
sample input #1:
3
2 2
3
-1
2
sample output #1:
1.000
explain
【 Data range 】
about 30% Data are available. n<=1000.
about 100% Data are available. n<=100000,1<=S<=T<=n,-10000<= Value index <=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;
}
The following code can ensure the cycle 0.95s after Automatically exit the loop ...
(double)clock() / CLOCKS_PER_SEC <= 0.95
边栏推荐
- How can a programmer grow rapidly
- 【多线程】锁策略
- 上大学后明白了哪些坑人的事?
- Install redis under Linux and configure the environment
- STC 32位8051单片机开发实例教程 二 I/O工作模式及其配置
- Oracle physical architecture
- 有意思了!数据库也搞Serverless!
- Review the collection container again
- SQL getting started plan-1-select
- EURA欧瑞E1000系列变频器使用PID实现恒压供水功能的相关参数设置及接线
猜你喜欢
How to turn off the boot auto start software in win11
为定时器和延时器等其它情况的回调函数绑定当前作用域的this
Win11怎么关闭开机自启动软件
Interesting! Database is also serverless!
Develop those things: easycvr cluster device management page function display optimization
Win11 how to hide the taskbar? Win11 method to hide the taskbar
Solve the problem of slow or failed vscode download
【多线程】锁策略
Big factories are wolves, small factories are dogs?
How to use console Log print text?
随机推荐
JS proxy
math_利用微分算近似值
STC 32-bit 8051 single chip microcomputer development example tutorial II i/o working mode and its configuration
Arduino Stepper库驱动28BYJ-48步进电机测试程序
Graduation season | Huawei experts teach the interview secret: how to get a high paying offer from a large factory?
Develop those things: easycvr platform adds playback address authentication function
300题线性代数 第四讲 线性方程组
3D panoramic model display visualization technology demonstration
RichView 文档中的 ITEM
Write blog documents
8K HDR!|为 Chromium 实现 HEVC 硬解 - 原理/实测指南
Hls4ml/vivado HLS error reporting solution
Face recognition system opencv face detection
【多线程】 实现单例模式 ( 饿汉、懒汉 ) 实现线程安全的单例模式 (双重效验锁)
Battery simulation of gazebo robot
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
Interview question 1
Difference between redo and undo
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
Gaussdb (for MySQL):partial result cache, which accelerates the operator by caching intermediate results