显然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. Protobuf 文件生成工具 Prototool 命令详解

    Protobuf 文件生成工具 Prototool 命令详解 简介 Prototool 是 Protobuf 文件的生成工具, 目前支持go, php, java, c#, object c 五种语言 ...

  2. [Oracle]oracle查询表列名、及列数

    --查询表列数 select count( column_name ) from user_tab_columns where table_name = 'CJ_HOME_MEDICAL_RECORD ...

  3. 自定义log4j的appender写es日志

    本篇和大家分享的是自定义log4j的appender,用es来记录日志并且通过kibana浏览es记录:就目前互联网或者一些中大型公司通常会用到第三方组合elk,其主要用写数据到es中,然后通过可视化 ...

  4. 剑指OFFER之打印1到最大的N位数(九度OJ1515)

    题目描述: 给定一个数字N,打印从1到最大的N位数. 输入: 每个输入文件仅包含一组测试样例.对于每个测试案例,输入一个数字N(1<=N<=5). 输出: 对应每个测试案例,依次打印从1到 ...

  5. 18.使用for循环计算+1-3+5-7+9-11+13...99的结果

    j = 1 # -1 num1 = 0 #1-3 for i in range(1,100,2): num1 += j * i # -3 j = j * -1 # 1 print(num1) sum1 ...

  6. Spring IOC 的源码分析

    刚学习Spring的时候,印象最深的就是 DispatcherServlet,所谓的中央调度器,我也尝试从这个万能胶这里找到入口 configureAndRefreshWebApplicationCo ...

  7. 页面出现滚动条时,body里面的内容不能自动居中?

    弹窗后允许页面滚动 这种方式通常使用 position: absolute; ,可以看看我做的这个 Demo.主要用来应对弹窗内容很大很多的情况,超过了屏幕的宽高需要产生滚动条来方便浏览者查看.有一些 ...

  8. luogu P2709 小B的询问 最简单的莫队

    块内按右端点sort,块外按左端点sort 话说我刚开始这么修改... inline )*(c[a[i]]-),--c[a[i]];} inline )*(c[a[i]]+),++c[a[i]];} ...

  9. 2017 Multi-University Training Contest - Team 7 Just do it

    http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意:一次操作就是i从1~n有 A[i]=A[i]^A[i-1]^A[i-2]...^A[1] 那么这样操 ...

  10. Uva11572

    读入可以不需要存入数组 #include<bits/stdc++.h> #define inf 0x3f3f3f3f //const int maxn=; using namespace ...