codeforces 578c//Weakness and Poorness// Codeforces Round #320 (Div. 1)
题意:一个数组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)的更多相关文章
- [codeforces] 578C Weakness and Poorness || 三分
原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...
- codeforces 578c - weekness and poorness - 三分
2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...
- 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. 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] E 三分+连续子序列的和的绝对值的最大值
E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces E. Weakness and Poorness(三分最大子列和)
题目描述: E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- 【解题报告】CF Round #320 (Div. 2)
Raising Bacteria 题意:盒子里面的细菌每天会数量翻倍,你可以在任意一天放任意多的细菌,最后要使得某天盒子里面的细菌数量等于x,求至少要放多少个细菌 思路:显然,翻倍即为二进制左移一位, ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C A Weakness and Poorness (三分)
显然f(x)是个凹函数,三分即可,计算方案的时候dp一下.eps取大了会挂精度,指定循环次数才是正解. #include<bits/stdc++.h> using namespace st ...
- 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 ...
随机推荐
- JSF Web框架与Facelets表现层技术
JSF(JavaServer Faces) JSF应用程序的生命周期从客户端对页面发出HTTP请求时开始,并在服务器响应页面时结束.JSF生命周期分为运行阶段和渲染阶段两个主要阶段. 执行阶段 当第一 ...
- CSS style 属性
CSS style 属性 定义和用法 必需的 type 属性规定样式表的 MIME 类型. type 属性指示 <style> 与 </style> 标签之间的内容. 值 &q ...
- "1130-host ... is not allowed to connect to this MySql server"登录失败
原因: 该用户没有远程连接权限. 解决:授权! mysql>GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' ...
- 20145122《Java程序设计》第七周学习总结
教材学习内容总结 1.在只有Lambda表达式的情况下,参数的类型必须写出来. 2.Lambda表达式本身是中性的,同样的Lambda表达式可用来表示不同目标类型的对象操作. 3.Lambda表达式只 ...
- 20145332卢鑫 WEB基础
20145332卢鑫 WEB基础 实验过程 1.环境配置 2.简单的网页编写 3.javascript相关 1.相关概念:JavaScript是一种广泛用于客户端Web开发的脚本语言,常用来给HTML ...
- MBR主引导扇区解析2
unsigned AnsiChar data[] = { 0x33, 0xC0, 0x8E, 0xD0, 0xBC, 0x00, 0x7C, 0x8E, 0xC0, 0x8E, 0xD8, 0xBE, ...
- POJ 2785 4 Values whose Sum is 0 (二分)题解
思路: 如果用朴素的方法算O(n^4)超时,这里用折半二分.把数组分成两块,分别计算前后两个的和,然后枚举第一个再二分查找第二个中是否有满足和为0的数. 注意和有重复 #include<iost ...
- UVA 3942 Remember the Word (Trie+DP)题解
思路: 大白里Trie的例题,开篇就是一句很容易推出....orz 这里需要Trie+DP解决. 仔细想想我们可以得到dp[i]=sum(dp[i+len[x]]). 这里需要解释一下:dp是从最后一 ...
- 【查看内存参数详解】Linux free -m 详细说明
free 命令相对于top 提供了更简洁的查看系统内存使用情况:$ free total used ...
- C语言中生产随机数 rand()函数
参考资料:C语言中产生随机数 一:如果你只要产生随机数而不需要设定范围的话,你只要用rand()就可以了:rand()会返回一随机数值, 范围在0至RAND_MAX 间.RAND_MAX定义在stdl ...