其实三分就是一个求单峰函数的最值的东西,用法比较统一。这个题就是观察发现不美好值是一个单峰函数,然后枚举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. 梦想MxWeb3D协同设计平台 2018.10.12更新

    SDK开发包下载地址: http://www.mxdraw.com/ndetail_10107.html 1. 全新的在线的三维协同设计平台,高效异步方式,基于JavaScript和WebGL技术,前 ...

  2. (转)Oracle数据库DBA必备基本技能

    [Oracle数据库DBA必备基本技能] shutdown Normal 需要等待所有的用户断开连接 Immediate 等待用户完成当前的语句 Transactional    等待用户完成当前的事 ...

  3. c++通过CMake实现debug开关

    刚学cmake,很多东西还不是很懂,不过今天刚刚实现了通过CMake控制debug的开关,兴奋之余记录一下. 背景介绍: 最近参与到了一个大的C++项目,很多代码已经非常成熟,我来添加一些辅助功能,但 ...

  4. jQuery元素节点的插入

    jquery插入节点的的方法,总的来说有8种,但是只要学会了其中的两个就能理解全部了, 这里我们学习append()和appendTo()两个方法: append()方法是向元素的内部追加内容: &l ...

  5. css去掉div的滚动条

    懒得讲原理了,直接贴代码: css部分: .slide-box { margin-top: 200px; display: -webkit-box; overflow-x: scroll; overf ...

  6. 面试总结——Java高级工程师(一)

    一.无笔试题 不知道是不是职位原因还是没遇到,面试时,都不需要做笔试题,而是填张个人信息表格,或者直接面试 二.三大框架方面问题 1.Spring 事务的隔离性,并说说每个隔离性的区别 解答:spri ...

  7. Python数据库连接池DBUtils(基于pymysql模块连接数据库)

    安装 pip3 install DBUtils DBUtils是Python的一个用于实现数据库连接池的模块. 此连接池有两种连接模式: # BDUtils数据库链接池: 模式一:基于threaing ...

  8. Spring 源码学习(一)

    工作好多年了,越来越心浮气躁了,好多东西都是一知半解的,所以现在需要静下心来好好学习一门技术. 就选Spring了, spring 设计java 开发的方方面面. 期待目标 对Spring 有个更深层 ...

  9. java8 新特性 lambda过滤

    1. 定义实体类 package com.atguigu.java8; public class Employee { private int id; private String name; pri ...

  10. 【17】AngularJS Bootstrap

    AngularJS Bootstrap AngularJS 的首选样式表是 Twitter Bootstrap, Twitter Bootstrap 是目前最受欢迎的前端框架. Bootstrap 你 ...