嘟嘟嘟

题面:给一个序列中的,每一个数都减去一个实数x,使得到的新序列的max(最大连续和,|最小连续和|)最小。(|ai| <= 10000)

感性的想想,会发现最大连续和随x变大而变小,最小连续和随x变大而变大。

严格的证明:首先对于任意区间[L, R],|∑ai - x|一定是一个绝对值函数,则最大连续和就是把所有[L, R]的函数复合在一起,然后取max,画图可知,也是一个单峰函数。(似乎也不怎么严格)

那么max(最大连续和,|最小连续和|)就是一个单峰函数,于是用三分求解。

至于最大连续和的求法,O(n)扫一遍即可,看代码就懂了。

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<vector>
#include<stack>
#include<queue>
using namespace std;
#define enter puts("")
#define space putchar(' ')
#define Mem(a, x) memset(a, x, sizeof(a))
#define rg register
typedef long long ll;
typedef double db;
const int INF = 0x3f3f3f3f;
const db eps = 1e-;
const int maxn = 2e5 + ;
inline ll read()
{
ll ans = ;
char ch = getchar(), last = ' ';
while(!isdigit(ch)) {last = ch; ch = getchar();}
while(isdigit(ch)) {ans = ans * + ch - ''; ch = getchar();}
if(last == '-') ans = -ans;
return ans;
}
inline void write(ll x)
{
if(x < ) x = -x, putchar('-');
if(x >= ) write(x / );
putchar(x % + '');
} int n, a[maxn]; db calc(db x)
{
db Min = , Max = , ans = ;
for(int i = ; i <= n; ++i)
{
Min = Min + a[i] - x > ? : Min + a[i] - x;
Max = Max + a[i] - x < ? : Max + a[i] - x;
ans = max(ans, max(Max, -Min));
}
return ans;
} int main()
{
n = read();
for(int i = ; i <= n; ++i) a[i] = read();
db L = -, R = , x;
for(int i = ; i <= ; ++i)
{
db m1 = L + (R - L) / 3.00;
db m2 = R - (R - L) / 3.00;
if(calc(m1) <= calc(m2)) x = m1, R = m2;
else x = m2, L = m1;
}
printf("%.8lf\n", calc(x));
return ;
}

CF578C Weakness and Poorness的更多相关文章

  1. cf578c Weakness and Poorness 三分

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

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

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

  4. Codeforces 578.C Weakness and Poorness

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

  5. 【CodeForces】578 C. Weakness and Poorness

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

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

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

  7. CF578C:Weakness and Poorness——题解

    https://vjudge.net/problem/CodeForces-578C —————————————————————————— 题目大意:序列的数-x,求最大连续子序列和的绝对值的最小值. ...

  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. zabbix 报警程序

    一,报警程序 本次使用的为onealert http://c.onealert.com/console/ucid/login.jsp 二,服务端安转 下面为他教的怎么安装这个东西 第一步: 找到脚本目 ...

  2. Python归纳 | 爬虫基础知识

    1. urllib模块库 Urllib是python内置的HTTP请求库,urllib标准库一共包含以下子包: urllib.error 由urllib.request引发的异常类 urllib.pa ...

  3. Vim as a Python IDE

    参考视频:http://v.youku.com/v_show/id_XNDY4NTM4NzY0.html 好的,在我们默认的centos6的操作系统中使用的python2,我们一般会再去安装一个pyt ...

  4. java语言编程使用正则表达式来实现提取(美团 3-5年经验 15-30k 北京 hadoop高级工程)中的3-5和15-30

    不多说,直接上干货! 如有这样的一条数据进来:   美团 3-5年经验 15-30k 北京 hadoop高级工程 //正则表达式提取工资值,因为15-30k后面有k,3-5年经验,不干净 public ...

  5. cloudermanager安装过程中出现W:GPG error错误 http://ppa.launchpad.net.trusty Release **** 4DF9B28CA252A784(图文详解)

    不多说,直接上干货! 问题详情  解决办法 sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4DF9B28CA252A784 ...

  6. 常用Redis命令

    在 Windows 下配置 Redis 集群 在 Windows 下配置多个 Redis(简化配置) MicrosoftArchive/redis 官方Redis集群搭建文档 Redis命令 Cent ...

  7. hibernateAPI详解

    1 Configuration package www.test.b_api; import org.hibernate.Session; import org.hibernate.SessionFa ...

  8. k8s单节点集群部署应用

    之所以用k8s来部署应用,就是因为k8s可以灵活的控制集群规模,进行扩充或者收缩.生产上我们要配置的参数较多,命令行的方式显然不能满足需求,我们应该使用基于配置文件的方式.接下来做一个部署的demo: ...

  9. TOJ 2939 解救小Q

    描述 小Q被邪恶的大魔王困在了迷宫里,love8909决定去解救她.迷宫里面有一些陷阱,一旦走到陷阱里,就会被困身亡:(,迷宫里还有一些古老的传送阵,一旦走到传送阵上,会强制被传送到传送阵的另一头. ...

  10. Android模拟器访问本机服务器

    Android模拟器访问本机服务器,用127.0.0.1访问不到,因为127.0.0.1已经被映射到模拟器了. 可以用以下两种方式访问 1. 用 10.0.2.2 2. 直接用 本机的IP地址,如:1 ...