题意:一个数组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. pandas练习(四)--- 应用Apply函数

    探索学生对酒的消费情况 数据见github 步骤1 - 导入必要的库 import pandas as pd import numpy as np 步骤2 - 数据集 path4 = "./ ...

  2. Hive 复制分区表和数据

    1. 非分区表: 复制表结构: create table new_table as select * from exists_table where 1=0; 复制表结构和数据: create tab ...

  3. Django框架----ORM数据库操作

    一.ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是通过使用 ...

  4. Eclipse编码规范——Code Templates设置

    Eclipse编码规范——Code Templates设置 Eclipse编码规范主要包括三个方面:设置Code Templates.Eclipse formatter.Checkstyle, 本篇主 ...

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

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

  6. 07:urllib与urllib2基本使用

    参考博客:https://blog.csdn.net/chendong_/article/details/51973499 1.1 urllib2发送get请求 # -*- coding:UTF-8 ...

  7. linux提示usb_serial_generic_write_bulk_callback - urb stoped: -32

    1.环境: 上位机:ubuntu16.04 Linux jello 4.4.0-89-generic #112-Ubuntu SMP Mon Jul 31 19:38:41 UTC 2017 x86_ ...

  8. POJ 1679 The Unique MST (次小生成树)题解

    题意:构成MST是否唯一 思路: 问最小生成树是否唯一.我们可以先用Prim找到一棵最小生成树,然后保存好MST中任意两个点i到j的这条路径中的最大边的权值Max[i][j],如果我们能找到一条边满足 ...

  9. java命令行执行程序解决依赖外部jar包的问题

    用java命令行直接执行程序,如果这个程序需要引用外部jar包.就不能单纯用java xx来执行 如果你的jar包和程序就在一个目录: 编译 javac -cp D:\yy\yy.jar,D\xx\x ...

  10. UOJ #103:【APIO2014】Palindromes

    题意: 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所有回文子串中的最 大出现值. 学会马拉车之后发现还需要后缀数组才能AC ...