当前位置:网站首页>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
边栏推荐
- 写博客文档
- Review the collection container again
- Bind this of the current scope for callback functions in other cases such as timers and delayers
- 【多线程】锁策略
- GaussDB(for MySQL) :Partial Result Cache,通过缓存中间结果对算子进行加速
- Is Dao safe? Build finance encountered a malicious governance takeover and was looted!
-
- 关于new Set( )还有哪些是你不知道的
- Error in installing sharp
- 面试题篇一
猜你喜欢

Easycvr accesses the equipment through the national standard gb28181 protocol. What is the reason for the automatic streaming of the equipment?

3D panoramic model display visualization technology demonstration

STC 32-bit 8051 single chip microcomputer development example tutorial three program compilation setting and download
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

EasyCVR通过国标GB28181协议接入设备,出现设备自动拉流是什么原因?

Oracle physical architecture

How to use console Log print text?

SQL getting started plan-1-select

Image acquisition and playback of coaxpress high speed camera based on pxie interface
![Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding](/img/56/0c7f39406814b5bf92eca5f6670e10.jpg)
Leetcode 1380 lucky numbers in matrix [array] the leetcode path of heroding
随机推荐
Install redis under Linux and configure the environment
Big factories are wolves, small factories are dogs?
Mo Tianlun salon | Tsinghua qiaojialin: Apache iotdb, originated from Tsinghua, builds an open source ecological road
渗透工具-TrustedSec 公司的渗透测试框架 (PTF)
Stack Overflow 2022 开发者调查:行业走向何方?
【多线程】锁策略
Difference between redo and undo
Redis installation and startup in Windows environment (background startup)
Use Zadig to build a continuous delivery platform from 0 to 1
大厂做狼,小厂做狗?
Use of common built-in classes of JS
关于new Set( )还有哪些是你不知道的
What if win11 can't pause the update? Win11 pause update is gray. How to solve it?
走进如心小镇,数智化变革连接“未来社区”
Solve the problem of slow or failed vscode download
SwiftUI 4 新功能大全之 Toggle与 Mixed Toggle 多个绑定组件
牛客编程题--必刷101之字符串(高效刷题,举一反三)
Stack overflow 2022 developer survey: where is the industry going?
C#联合halcon应用——大华相机采集类
Richview trvdocparameters page parameter settings