显然f(x)是个凹函数,三分即可,计算方案的时候dp一下。eps取大了会挂精度,指定循环次数才是正解。

#include<bits/stdc++.h>

using namespace std;
const double eps = 1e-;
const int maxn = 2e5+;
double a[maxn];
double d1[maxn],d2[maxn];
int n;
inline double cal(double x)
{
double a1 = ., a2 = .;
for(int i = ; i <= n; i++){
d1[i] = max(.,d1[i-])+a[i]-x;
a1 = max(a1,d1[i]);
d2[i] = min(.,d2[i-])+a[i]-x;
a2 = min(a2,d2[i]);
}
return max(fabs(a1),fabs(a2));
} int main()
{
//freopen("in.txt","r",stdin);
scanf("%d",&n);
for(int i = ; i <= n; i++) scanf("%lf",a+i);
double L = -1e4, R = 1e4;
double M1v,M2v;
while(R-L>eps){
double M1 = L+(R-L)/, M2 = L+(R-L)/*;
M1v = cal(M1), M2v = cal(M2);
if(abs(M1v-M2v)<eps){
L = M1; R = M2;
}else {
if(M1v > M2v){
L = M1;
}else {
R = M2;
}
}
}
printf("%.15lf",(cal(L)+cal(R))/);
return ;
}

Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A 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. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心

    B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...

  3. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game

    题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...

  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] A. Raising Bacteria【位运算/二进制拆分/细胞繁殖,每天倍增】

    A. Raising Bacteria time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Codeforces Round #320 (Div. 2) [Bayan Thanks-Round] D 数学+(前缀 后缀 预处理)

    D. "Or" Game time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

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

  8. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)

    首先应该保证二进制最高位尽量高,而位数最高的数乘x以后位数任然是最高的,所以一定一个数是连续k次乘x. 当出现多个最高位的相同的数就枚举一下,先预处理一下前缀后缀即可. #include<bit ...

  9. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] A A Problem about Polyline(数学)

    题目中给出的函数具有周期性,总可以移动到第一个周期内,当然,a<b则无解. 假设移动后在上升的那段,则有a-2*x*n=b,注意限制条件x≥b,n是整数,则n≤(a-b)/(2*b).满足条件的 ...

随机推荐

  1. unix环境高级编程附录 B 通用代码

    0.说明: 在测试 unix 环境高级编程中的代码时,需要一些作者事先写好的代码, 如: apue.h 包含某些标准系统头文件,定义许多常量及函数原型 还有两个作者自编的函数来对错误进行处理 1.ep ...

  2. js中的"=="和equals()以及is()三者的区别

    在 javaScript或者jQuery中字符串比较没有equals()方法,要比较两个字符串是否相等可以直接用==或者is()进行判断. 例如: "a"=="a&quo ...

  3. c# sleep 例子-线程挂起

    using System; using System.Threading; public class arr { public static void Main() { //int[] arr; // ...

  4. excel常用函数之find,left,right,mid,len

    mid =MID(A2,FIND("时间",A2)+2,10) 第一个 : 提取对象 第二个: 开始位置 第三个: 提取多少 find =FIND(“时间”,A2,1) 第一个: ...

  5. AES 加密 PHP 和 JAVA 互通

    PHP代码: <?php class Security { public static function encrypt($input, $key) { $size = mcrypt_get_b ...

  6. 洛谷P3272 [SCOI2011]地板(插头dp)

    传送门 感谢大佬的教导->这里 容易注意到,本题的合法路径“L型地板”有一些特殊的地方:拐弯且仅拐弯一次. 这由于一条路径只有两种状态:拐弯过和没拐弯过,因此我们可以尝试着这样定义新的插头: 我 ...

  7. Hibernate 继承映射可能会遇到的错误

    问题: 我们在配置hibernate的时候,默认是会配置下面的两个属性的 <property name="hibernate.default_catalog">hibe ...

  8. Codeforces 140D(贪心)

    要点 跟大家打acm的策略一样,为了做更多的题数肯定做最简单的题目,为了罚时更少肯定从易到难做 虽然有个12:00之限不同于往常比赛,但细想还是要从易到难贪:做这些题的总时间肯定是不变的,只是顺序可变 ...

  9. shell 获得调用的python脚本的print值和错误log

    1. shell 获得调用的python脚本的print值 python test.py > out.log 2.shell 获得调用的python脚本的错误log python test.py ...

  10. Spark Mllib里如何提取每个字段并转换为***类型(图文详解)

    不多说,直接上干货! 具体,见 Hadoop+Spark大数据巨量分析与机器学习整合开发实战的第17章 决策树多元分类UCI Covertype数据集