其实三分就是一个求单峰函数的最值的东西,用法比较统一。这个题就是观察发现不美好值是一个单峰函数,然后枚举t进行三分就行了。

题干:

给定一个长度为n的数组ai,求一个实数x,使得序列a1-x,a2-x,...,an-x的不美好程度最小。

不美好程度定义为,一个序列的所有连续子序列的糟糕程度的最大值。

糟糕程度定义为,一个序列的所有位置的和的绝对值。

输入 第一行n。

第二行n个数,表示ai。

输出 一个实数,精确到6位小数,表示最小不美好程度值。

代码:

#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
const int maxn = 2e5 + ;
const db eps = 1e-;
int arr[maxn];
db arr1[maxn];
int n;
db calc(db arr[])
{
db t = ;
db res = arr[];
duke(i,,n - )
{
t = arr[i] + t;
res = max(res,t);
if(t < eps)
t = ;
}
return res;
}
db solve(db t)
{
duke(i,,n - )
{
arr1[i] = arr[i] - t;
}
db x1 = calc(arr1);
duke(i,,n - )
arr1[i] = -arr1[i];
db x2 = calc(arr1);
db x = max(fabs(x1),fabs(x2));
return x;
}
int main()
{
read(n);
int maxnum = -,minnum = ;
duke(i,,n - )
{
read(arr[i]);
maxnum = max(maxnum,arr[i]);
minnum = min(minnum,arr[i]);
}
int dcnt = ;
db l = minnum ,r = maxnum;
while(dcnt--)
{
db m1 = l + (r - l) / ;
db m2 = r - (r - l) / ;
db x1 = solve(m1);
db x2 = solve(m2);
if(x1 > x2)
{
l = m1;
}
else
{
r = m2;
}
}
db res = solve(l);
printf("%.8lf\n",res);
return ;
}

cf578c Weakness and Poorness 三分的更多相关文章

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

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

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

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

  4. CF578C Weakness and Poorness

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

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

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

  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】578 C. Weakness and Poorness

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

  8. codeforces 578c - weekness and poorness - 三分

    2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...

  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. P1048 采药(洛谷,动态规划递推,01背包原题)

    题目直接放链接 P1048 采药 这题只是01背包+背景故事而已 原题来的 PS:我写了一篇很详细的01背包说明,如果下面ac代码有看不懂的地方可以去看看 对01背包的分析与理解(图文) 下面上ac代 ...

  2. linux基础常用语句--新手

    查询:ls查看全部内容:ls -n删除:rm -rf 文件名创建目录: mkdir解压:rpm -验证是否安装:rpm -p 文件名rpm -ivh --nodeps 不需要前置条件的安装查询当前路径 ...

  3. Vmware下的Linux系统,安装WPS报错:[Errno 256] No more mirrors to try

    最近新装了虚拟环境Vmware下的Linux系统,准备看doc文档发现不能读取,才想起来一起都是重新开始的~没别的~开始安装吧: 1.关虚拟机Linux,添加cdrom镜像ISO文件--开虚拟机--- ...

  4. Jmeter BeanShell PreProcessor使用笔记

    打印log log.info("content:" + content); 将字符串转化为JsonString import com.alibaba.fastjson.JSON; ...

  5. lnmp的安装--nginx

    1.nginx的安装 安装所需环境 Nginx 是 C语言 开发,建议在 Linux 上运行,当然,也可以安装 Windows 版本,本篇则使用 CentOS 7 作为安装环境. 一. gcc 安装安 ...

  6. [luoguP1072] Hankson 的趣味题(数论)

    传送门 由题意得 gcd(x, a0) = a1 ——> gcd(x / a1, a0 / a1) = 1 lcm(x, b0) = b1 ——> x * b0 / gcd(x, b0) ...

  7. Elasticsearch使用总结

    原文出自:https://www.2cto.com/database/201612/580142.html ELK干货:http://www.cnblogs.com/xing901022/p/4704 ...

  8. 【ZJOI2017 Round2练习&BZOJ4826】D1T2 sf(主席树,单调栈)

    题意: 思路:From http://blog.csdn.net/neither_nor/article/details/70211150 对每个点i,单调栈求出左边和右边第一个大于i的位置,记为l[ ...

  9. Linux下汇编语言学习笔记72 ---

    这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...

  10. 《Spring in action》之Spring之旅

    Spring框架作用是简化java开发的复杂性.下面是spring in action 对spring初步介绍. 一.主要有4种关键策略: 1. 基于POJO的轻量级和最小侵入性编程 . 2. 通过依 ...