题意:一个数组arr,一个数字x,要使arr-x的最大子段最小,问该最小值。

三分x,复杂度logn,内层是最大子段的模板,只能用n复杂度的。因为是绝对值最大,正负各求一次,取大的。精度卡得不得了,要1e-12左右才能过。看着数据才调出精度的。

乱码:

//#pragma comment(linker,"/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include <stack>
#include <iomanip>
using namespace std;
const int SZ=,INF=0x7FFFFFFF;
const double EPS=8e-;
typedef long long lon;
double arr[SZ],b[SZ],dp[SZ]; double max(double a[],int n)
{
double sum,maxsum;
int i ;
sum = maxsum = ;
for(i = ;i<n;i++)
{
sum +=a[i];
if(sum>maxsum)
maxsum = sum;
else if(sum<)
sum = ;
}
return maxsum;
} double work(int n)
{
double res1=max(b,n);
for(int i=;i<n;++i)b[i]=-b[i];
double res2=max(b,n);
return max(res1,res2);
} int main()
{
std::ios::sync_with_stdio();
//freopen("d:\\1.txt","r",stdin);
//for(;scanf("%d",&n)!=EOF;)
{
int n;
clock_t bg=clock(),end;
cin>>n;
for(int i=;i<n;++i)
{
cin>>arr[i];
}
double lo=-,hi=,res=; for(;lo<hi&&fabs(lo-hi)>EPS;)
{
//end=clock();
//if(end-bg>1500)break;
double mid1=lo+(hi-lo)/;
double mid2=lo+*(hi-lo)/;
for(int i=;i<n;++i)
{
b[i]=arr[i]-mid1;
}
double res1=work(n);
for(int i=;i<n;++i)
{
b[i]=arr[i]-mid2;
}
double res2=work(n);
res=res1;
//cout<<lo<<" "<<hi<<' '<<res<<endl;
if(res1<res2)hi=mid2;
else lo=mid1+1e-;
}
cout<<fixed<<setprecision()<<res<<endl;
}
return ;
}

codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)的更多相关文章

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

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

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

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

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

  5. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] E 三分+连续子序列的和的绝对值的最大值

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

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

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

  7. 【解题报告】CF Round #320 (Div. 2)

    Raising Bacteria 题意:盒子里面的细菌每天会数量翻倍,你可以在任意一天放任意多的细菌,最后要使得某天盒子里面的细菌数量等于x,求至少要放多少个细菌 思路:显然,翻倍即为二进制左移一位, ...

  8. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)

    显然f(x)是个凹函数,三分即可,计算方案的时候dp一下.eps取大了会挂精度,指定循环次数才是正解. #include<bits/stdc++.h> using namespace st ...

  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. python 线程、多线程

    复习进程知识: python:主进程,至少有一个主线程 启动一个新的子进程:Process,pool 给每一个进程设定一下执行的任务:传一个函数+函数的参数 如果是进程池:map函数:传入一个任务函数 ...

  2. $.ajax({ }) 里面的success函数不执行 | 回调函数返回的值 用对象,下标,键值对访问不到时

    原因一般是  dataType:'json' 数据类型设置成了json  ,去掉这个设置即可 $.ajax({ }) 回调函数返回的值 用对象,下标,键值对访问不到时,考虑是否返回数据为字符串 考虑是 ...

  3. Linux基础命令---last

    last 显示以前登录过的用户信息,last指令会搜索/var/log/wtmp文件(或者是经过-f选项指定的文件),然后列出文件中所有的用户信息.如果执行last指令时提示“last /var/lo ...

  4. java commons.lang3 ArrayUtils使用

    java commons.lang3 ArrayUtils使用import org.apache.commons.lang3.ArrayUtils; /** *数组追加数组,不重复 */ public ...

  5. nginx反向代理-后端服务器组设置

    nginx服务器的反向代理时其最常用的重要功能之一,在实际工作中应用广泛,涉及的配置指令也比较多.下面会尽量详细地介绍对应的指令,及其使用状态. 反向代理一般是互联网需要向内网拉取资源,比如访问一个w ...

  6. Linux解压文件到指定目录

    Linux解压文件到指定目录 tar在Linux上是常用的打包.压缩.加压缩工具,他的参数很多,折里仅仅列举常用的压缩与解压缩参数 参数:-c :create 建立压缩档案的参数:-x : 解压缩压缩 ...

  7. C++面向对象高级开发课程(第一周)

    0. 内存分区 计算机中的内存在用于编程时,被人为的进行了分区(Segment),分为: -“栈区”(Stack) -“堆区”(Heap) -全局区(静态 区,Static) -文字常量区和程序代码区 ...

  8. 03: centos中配置使用svn

    1.1 centos7.3源码搭建svn----安装各种依赖包 1.安装zlib-1.2.8.tar.xz xz -d zlib-1.2.8.tar.xz tar xvf zlib-1.2.8.tar ...

  9. STM32唯一的ID

    请看如下程序: /*------------------------------------------------------------------------------------------ ...

  10. C# 获取当前IIS请求地址

    using System;using System.Collections.Generic;using System.Linq;using System.Web; /// <summary> ...