Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)
显然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 (三分)的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game
题目链接:http://codeforces.com/contest/578/problem/B 题目大意:现在有n个数,你可以对其进行k此操作,每次操作可以选择其中的任意一个数对其进行乘以x的操作. ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B "Or" Game (贪心)
首先应该保证二进制最高位尽量高,而位数最高的数乘x以后位数任然是最高的,所以一定一个数是连续k次乘x. 当出现多个最高位的相同的数就枚举一下,先预处理一下前缀后缀即可. #include<bit ...
- 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).满足条件的 ...
随机推荐
- ubuntu: 终端全屏快捷键
ubuntu12.04终端全屏 (2012-06-08 19:49:04) 转载▼ 进入终端全屏: ctrl+alt+f1 ctrl+alt+f2 ctrl+alt+f3 ctrl+alt+f4 ct ...
- iOS横屏设置的几种方式
1.界面旋转,MainScreen的宽高不变,键盘位置不变 CGFloat duration = [UIApplication sharedApplication].statusBarOrientat ...
- CLR via C# 第五章学习记录(更新中)
1.设置全局溢出检查,项目属性->生成->高级->检测运算上溢/下溢 2.局部使用溢出检测 Byte b = ; b = ));// 不检测溢出 checked// 检测溢出代码段 ...
- 51nod1154(dp)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1154 题意:中文题目诶- 思路:字符串长度不大于5e3,O(n ...
- 洛谷P4218 [CTSC2010]珠宝商(后缀自动机+点分治)
传送门 这题思路太清奇了……->题解 //minamoto #include<iostream> #include<cstdio> #include<cstring ...
- [Xcode 实际操作]六、媒体与动画-(12)检测UIView动画的结束事件:反转动画并缩小至不可见状态
目录:[Swift]Xcode实际操作 本文将演示UIView视图反转动画的制作,并检测其动画结束事件. 即视图在进行反转动画的同时,将移动到目标位置,并缩小至不可见状态. 在项目导航区,打开视图控制 ...
- pycharm安装教程,汉化教程,以及正版激活码---
密钥在下面 安装过程 PyCharm2019本地下载: http://www.100c1.com/upload/default/20190420/1c08a3209029093a8b34df941f1 ...
- PHP composer 日常使用命令和理解
composer的操作很多很杂,平时大都用不上,正要找又一时半会难找到 日常操作,走起 第一部分 : 安装 composer.json composer init 这个命令创建了一个 composer ...
- redids
Redis 地理位置(geo) Redis 键(key) Redis 字符串(String) Redis 哈希(Hash) Redis 列表(List) Redis 集合(Set) Redis 有序集 ...
- mac mysql 编码配置
mac mysql 编码配置 (mysql目录下没有my.cnf) 想要修改编码发现自己的/usr/local/mysql/support-files里面根本没有my.cnf 安装方式是去mysql官 ...