Codeforces E. Weakness and Poorness(三分最大子列和)
题目描述:
E. Weakness and Poorness
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
You are given a sequence of n integers a1, a2, ..., a**n.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., a**n - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poorness of a segment is defined as the absolute value of sum of the elements of segment.
Input
The first line contains one integer n (1 ≤ n ≤ 200 000), the length of a sequence.
The second line contains n integers a1, a2, ..., a**n (|a**i| ≤ 10 000).
Output
Output a real number denoting the minimum possible weakness of a1 - x, a2 - x, ..., a**n - x. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
Copy
31 2 3
Output
Copy
1.000000000000000
Input
Copy
41 2 3 4
Output
Copy
2.000000000000000
Input
Copy
101 10 2 9 3 8 4 7 5 6
Output
Copy
4.500000000000000
Note
For the first case, the optimal value of x is 2 so the sequence becomes - 1, 0, 1 and the max poorness occurs at the segment "-1" or segment "1". The poorness value (answer) equals to 1 in this case.
For the second sample the optimal value of x is 2.5 so the sequence becomes - 1.5, - 0.5, 0.5, 1.5 and the max poorness occurs on segment "-1.5 -0.5" or "0.5 1.5". The poorness value (answer) equals to 2 in this case.
思路:
这道题是要求一个数列减去一个数$x$后的子列和的绝对值最大(poorness)的情况下的可能的最小值(weakness)。(有点绕哈
Codeforces E. Weakness and Poorness(三分最大子列和)的更多相关文章
- [codeforces] 578C Weakness and Poorness || 三分
原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...
- codeforces 578c - weekness and poorness - 三分
2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp
C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E. Weakness and Poorness 三分
E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)
题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值. 三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的.因为是绝对值最大,正负各求一次,取大的.精度卡得不得了,要 ...
- cf578c Weakness and Poorness 三分
其实三分就是一个求单峰函数的最值的东西,用法比较统一.这个题就是观察发现不美好值是一个单峰函数,然后枚举t进行三分就行了. 题干: 给定一个长度为n的数组ai,求一个实数x,使得序列a1-x,a2-x ...
- Codeforces 578.C Weakness and Poorness
C. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【CodeForces】578 C. Weakness and Poorness
[题目]C. Weakness and Poorness [题意]给定含n个整数的序列ai,定义新序列为ai-x,要使新序列的最大子段和绝对值最小,求实数x.n<=2*10^5. [算法]二分| ...
- PAT复杂度_最大子列和问题、最大子列和变种
01-复杂度1. 最大子列和问题 给定K个整数组成的序列{ N1, N2, ..., NK },“连续子列”被定义为{ Ni, Ni+1, ..., Nj },其中 1 <= i <= j ...
随机推荐
- python:时间格式转化
1.获取秒级时间戳与毫秒级时间戳.微秒级时间戳 import time import datetime t = time.time() print (t) #原始时间数据 print (int(t)) ...
- zabbix 后台数据库清除数据
alerts 表 problem 表 escalations 表 events 表 event_recovery表 对 这些表进行清除 防止不停发送邮件 -- alerts table rebuil ...
- [转帖]很遗憾,没有一篇文章能讲清楚ZooKeeper
很遗憾,没有一篇文章能讲清楚ZooKeeper https://os.51cto.com/art/201911/606571.htm [51CTO.com原创稿件]互联网时代是信息爆发的时代,信息的高 ...
- c和c++中的枚举和 区别
1.c中的枚举 c语言枚举 void test(){ // enum 枚举类型名字{枚举值, 枚举值, 枚举值}; enum WEEK { Mon, Tue };// 枚举类型定义 enum WEEK ...
- 简单的爬虫程序以及使用PYQT进行界面设计(包含源码解析)
由于这个是毕业设计的内容,而且还是跨专业的.爬虫程序肯定是很简单的,就是调用Yahoo的API进行爬取图片.这篇博客主要讲的是基础的界面设计. 放上源码,然后分部解析一下重要的地方.注:flickra ...
- spring整合RabbitMQ
今天就来康康spring怎么整合RabbitMQ 注意一点,在发送消息的时候对template进行配置mandatory=true保证监听有效 生产端还可以配置其他属性,比如发送重试,超时时间.次数. ...
- 切换GCC编译器版本
当前版本信息 root@ubuntu:runninglinuxkernel_4.0# aarch64-linux-gnu-gcc -v Using built-in specs. COLLECT_GC ...
- C#获取文件夹下的所有文件的方法
目录 #基础知识 #只获取目录下一级的文件夹与文件 # 递归地输出当前运行程序所在的磁盘下的所有文件名和子目录名 正文 #基础知识 1.获得当前运行程序的路径 1 string rootPath ...
- Mybatis中使用collection进行多对多双向关联示例(含XML版与注解版)
Mybatis中使用collection进行多对多双向关联示例(含XML版与注解版) XML版本: 实体类: @Data @NoArgsConstructor public class Course ...
- 必须掌握的Linux用户组
在 Linux 系统中用户组起着重要作用.用户组提供了一种简单方法供一组用户互相共享文件.用户组也允许系统管理员更加有效地管理用户权限,因为管理员可以将权限分配给用户组而不是逐一分配给单个用户. 尽管 ...