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 ...
随机推荐
- 获取Android设备的唯一识别码|设备号|序号|UUID
如何获取一个能唯一标识每台Android设备的序号? 这个问题有很多答案,但是他们中的大部分只在某些情况下有效. 根据测试: 所有的设备都可以返回一个 TelephonyManager.getDevi ...
- python xml childNodes,childNodes[1].childNodes[0].data例子
xml: <?xml version='1.0' encoding='utf-8'?><!--this is a test about xml--><booklist t ...
- 计算概论(A)/基础编程练习1(8题)/7:奇数求和
#include<stdio.h> int main() { // 输入非负整数 int m, n; scanf("%d %d", &m, &n); / ...
- Git在windows下上传文件至github流程
github是开发者分享的一个平台,这里不多说,想要上传文件至github需要有一个开发者账号,还需要在windows下安装好了git. 做好准备工作之后,接下来操作 一:登录github,创建项目 ...
- 04: linux基础总结
目录: 1.1 Red Hat Linux 安装及服务控制 1.2 目录和文件管理 1.3 安装及管理程序 1.4 账号和权限管理 1.5 磁盘和文件管理 1.6 进程和计划任务管理 1.7 Linu ...
- zabbix-server新增zabbix-agent
zabbix监控系统搭建好了之后,就需要为各种角色host加入进来,现在新增一台zabbix-agent: 1.在172.16.23.128上安装zabbix-agent,zabbix-server: ...
- 2018-2019-1 20189218《Linux内核原理与分析》第四周作业
构造简单的Linux内核 显然用实验楼配好的环境做这个实验太简单了,按照没有困难制造困难也要上的原则,在自己的64位虚拟机上做这个实验. 按照课本(视频)上的步骤一直做下去,到编译生成init时出现了 ...
- Python3基础 bool类型变量赋值
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- POJ 2352 Stars(树状数组)题解
Language:Default Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 52268 Accepted: 22 ...
- centos 安装iftop
iftop是linux下的一个流量监控工具,用于查看实时网络流量.官网:http://www.ex-parrot.com/pdw/iftop/ 1.安装必须软件包yum install libpcap ...