题意:一个数组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. Java缓存学习之六:Spring单独使用EhCache

      通过在Application Context中配置EhCacheManagerFactoryBean和EhCacheFactoryBean,我们就可以把对应的EhCache的CacheManage ...

  2. 性能分析之– JAVA Thread Dump 分析

    最近在做性能测试,需要对线程堆栈进行分析,在网上收集了一些资料,学习完后,将相关知识整理在一起,输出文章如下. 一.Thread Dump介绍 1.1什么是Thread Dump? Thread Du ...

  3. mysql事务(二)——控制语句使用

    事务控制 一般来说,mysql默认开启了事务自动提交功能,每条sql执行都会提交事务.可以使用如下语句关闭事务自动提交功能. show session variables like 'autocomm ...

  4. 20165207 Exp3 免杀原理与实践

    Exp3 免杀原理与实践 1.实验内容 1.1.使用msf 1.1.1. 确定基准线 首先看kali的ip 直接msfvenom的结果,不加其他的东西: 使用VirusTotal得到的检测这个程序得到 ...

  5. eclispe 相关设置

    1. 关闭js文件校验: 1). windows->preference->Java Script->Validator->Errors/Warnings->Enable ...

  6. php header utf8 插入header("Content-type: text/html; charset=utf-8");

    PHP文件插入header("Content-type: text/html; charset=utf-8"); 相当于页面里面的<meta http-equiv=" ...

  7. python之路----面向对象进阶二

    item系列 __getitem__\__setitem__\__delitem__ class Foo: def __init__(self,name,age,sex): self.name = n ...

  8. mysql-innodb的事务日志

    [参考书籍:mysql技术内幕 INNODB存储引擎][参考了一些博客内容] 事务的隔离性由锁机制来实现,事务的原子性,一致性,持久性通过INNODB的redo log和undo log来完成. re ...

  9. vc++引用外部dll时报error LNK2019: 无法解析的外部符号

    初学cpp,因为之前装linux下各种软件的时候,知道LD_LIBRARY_PATH可以指定动态库的目录.今天在vc集成log4cpp的时候,编译main时报error LNK2019: 无法解析的外 ...

  10. 20165211 学习基础和C语言调查

    20165211 学习基础和C语言调查 理论脱离实践是最大的不幸.--达芬奇 达芬奇,是我眼里最有嫌疑的穿越者. 绘画.天文.雕塑.音乐.发明.建筑,数学.生理.物理.天文.地质--我很难想象有一个人 ...