https://vjudge.net/problem/CodeForces-578C

——————————————————————————

题目大意:序列的数-x,求最大连续子序列和的绝对值的最小值。

————————————————————————————

没有绝对值的话,明显是单调增的。

将数全部翻转,明显是单调减的。

所以显然是单峰函数,可以三分x做。

要注意精度,循环200就差不多了,不要循环太多次不然会TLE。

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
const int M=;
double a[M];
int n;
double suan(double m){
double ans=,sum=;
for(int i=;i<=n;i++){
sum+=a[i]-m;
if(sum<)sum=;
ans=max(ans,sum);
}
sum=;
for(int i=;i<=n;i++){
sum+=m-a[i];
if(sum<)sum=;
ans=max(ans,sum);
}
return ans;
}
double sanfen(double l,double r){
for(int i=;i<=;i++){
double midl=(r-l)/+l;
double midr=r-(r-l)/;
if(suan(midl)<suan(midr))r=midr;
else l=midl;
}
return l;
}
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++)scanf("%lf",&a[i]);
printf("%.15lf\n",suan(sanfen(-,)));
return ;
}

CF578C:Weakness and Poorness——题解的更多相关文章

  1. CF578C Weakness and Poorness

    嘟嘟嘟 题面:给一个序列中的,每一个数都减去一个实数x,使得到的新序列的max(最大连续和,|最小连续和|)最小.(|ai| <= 10000) 感性的想想,会发现最大连续和随x变大而变小,最小 ...

  2. cf578c Weakness and Poorness 三分

    其实三分就是一个求单峰函数的最值的东西,用法比较统一.这个题就是观察发现不美好值是一个单峰函数,然后枚举t进行三分就行了. 题干: 给定一个长度为n的数组ai,求一个实数x,使得序列a1-x,a2-x ...

  3. 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 ...

  4. 【CodeForces】578 C. Weakness and Poorness

    [题目]C. Weakness and Poorness [题意]给定含n个整数的序列ai,定义新序列为ai-x,要使新序列的最大子段和绝对值最小,求实数x.n<=2*10^5. [算法]二分| ...

  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 ...

  6. Codeforces 578.C Weakness and Poorness

    C. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces E. Weakness and Poorness(三分最大子列和)

    题目描述: E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes inp ...

  8. [codeforces] 578C Weakness and Poorness || 三分

    原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...

  9. Weakness and Poorness CodeForces - 578C 三分搜索 (精度!)

    You are given a sequence of n integers a1, a2, ..., an. Determine a real number x such that the weak ...

随机推荐

  1. 使用union 外加count

    explain extended and name='aaa')) t; +----+--------------+------------+-------+---------------+----- ...

  2. Prism MEF example

    Related Attributes These attributes are under namespace System.ComponentModel.Composition Import The ...

  3. XSS--编码绕过,qcms,鲶鱼cms

    一.编码绕过 1)HTML进制编码 标签中的某些属性值可以使用html十进制.十六进制表示 2)JavaScript编码 JavaScript支持unicode.八进制.十六进制.十进制等 3)URL ...

  4. mysql优化理解笔记(持续更新)

    主要包括存储引擎.索引.sql语句 一.存储引擎 目前最常见的是InnoDB和MyISAM两个存储引擎 (1)InnoDB:支持事务处理,提供行级锁.外键约束索引,行锁 (2)MyISAM:支持全文搜 ...

  5. Objective-C 类和对象

    面向对象 面向对象(Object-Oriented)是基于面向过程(procedure-oriented)而言的 面向对象 强调对象<指挥者> OC, Java语言就是面向对象 面向过程 ...

  6. word record 3

    word record 3 tabloid : a half size page of a newspaper, or a newspaper or magazine with short, exci ...

  7. OpenMPI 集群配置

    现在有2台机器,希望可以尝试一下在多台机器上跑MPI的感觉,所以跑之前就得配置,先参考网址: https://www.cnblogs.com/awy-blog/p/3402949.html: 1. 配 ...

  8. Memcache的客户端连接系列(四) PHP

    关键词: Memcached   PHP 客户端 声明:本文并非原创,转自华为云帮助中心的分布式缓存服务(Memcached)的用户指南.客户端连接方法通用,故摘抄过来分享给大家. PHP客户端 Re ...

  9. 在mesh client示例中加入spi_slave接口(without IDE)

    在mesh client示例中加入spi_slave接口(without IDE) 主要是理解cmake构建的过程,然后修改工程中的inlcude路径及c源文件. 1. 解压mesh_sdk unzi ...

  10. [leetcode-662-Maximum Width of Binary Tree]

    Given a binary tree, write a function to get the maximum width of the given tree. The width of a tre ...