cf578c Weakness and Poorness 三分
其实三分就是一个求单峰函数的最值的东西,用法比较统一。这个题就是观察发现不美好值是一个单峰函数,然后枚举t进行三分就行了。
题干:
给定一个长度为n的数组ai,求一个实数x,使得序列a1-x,a2-x,...,an-x的不美好程度最小。 不美好程度定义为,一个序列的所有连续子序列的糟糕程度的最大值。 糟糕程度定义为,一个序列的所有位置的和的绝对值。 输入 第一行n。 第二行n个数,表示ai。 输出 一个实数,精确到6位小数,表示最小不美好程度值。
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<ctime>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define duke(i,a,n) for(int i = a;i <= n;i++)
#define lv(i,a,n) for(int i = a;i >= n;i--)
#define clean(a) memset(a,0,sizeof(a))
const int INF = << ;
typedef long long ll;
typedef double db;
template <class T>
void read(T &x)
{
char c;
bool op = ;
while(c = getchar(), c < '' || c > '')
if(c == '-') op = ;
x = c - '';
while(c = getchar(), c >= '' && c <= '')
x = x * + c - '';
if(op) x = -x;
}
template <class T>
void write(T x)
{
if(x < ) putchar('-'), x = -x;
if(x >= ) write(x / );
putchar('' + x % );
}
const int maxn = 2e5 + ;
const db eps = 1e-;
int arr[maxn];
db arr1[maxn];
int n;
db calc(db arr[])
{
db t = ;
db res = arr[];
duke(i,,n - )
{
t = arr[i] + t;
res = max(res,t);
if(t < eps)
t = ;
}
return res;
}
db solve(db t)
{
duke(i,,n - )
{
arr1[i] = arr[i] - t;
}
db x1 = calc(arr1);
duke(i,,n - )
arr1[i] = -arr1[i];
db x2 = calc(arr1);
db x = max(fabs(x1),fabs(x2));
return x;
}
int main()
{
read(n);
int maxnum = -,minnum = ;
duke(i,,n - )
{
read(arr[i]);
maxnum = max(maxnum,arr[i]);
minnum = min(minnum,arr[i]);
}
int dcnt = ;
db l = minnum ,r = maxnum;
while(dcnt--)
{
db m1 = l + (r - l) / ;
db m2 = r - (r - l) / ;
db x1 = solve(m1);
db x2 = solve(m2);
if(x1 > x2)
{
l = m1;
}
else
{
r = m2;
}
}
db res = solve(l);
printf("%.8lf\n",res);
return ;
}
cf578c 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. 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] 578C Weakness and Poorness || 三分
原题 题目定义了两个变量: poorness表示一个区间内和的绝对值. weakness表示一个所有区间最大的poornesss 题目要求你求一个x使得 a1 − x, a2 − x, ..., an ...
- CF578C Weakness and Poorness
嘟嘟嘟 题面:给一个序列中的,每一个数都减去一个实数x,使得到的新序列的max(最大连续和,|最小连续和|)最小.(|ai| <= 10000) 感性的想想,会发现最大连续和随x变大而变小,最小 ...
- Codeforces E. Weakness and Poorness(三分最大子列和)
题目描述: E. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces 578.C Weakness and Poorness
C. Weakness and Poorness time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【CodeForces】578 C. Weakness and Poorness
[题目]C. Weakness and Poorness [题意]给定含n个整数的序列ai,定义新序列为ai-x,要使新序列的最大子段和绝对值最小,求实数x.n<=2*10^5. [算法]二分| ...
- codeforces 578c - weekness and poorness - 三分
2017-08-27 17:24:07 writer:pprp 题意简述: • Codeforces 578C Weakness and poorness• 给定一个序列A• 一个区间的poornes ...
- 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 ...
随机推荐
- 梦想CAD控件关于id与handle问题
ID和句柄具有各自的特点: (1) ID:在一个任务中,本次任务中都是独一无二的.在不同的任务中,同一个图形对象的ID可能不同. (2) 句柄:在一个任务中,不能保证每个对象的句柄都唯一,但是在一个图 ...
- jquery 实现点评标签 类似淘宝大众点评的 快速准时 货品完好等
111 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <tit ...
- UVA - 10048 Audiophobia(Floyd求路径上最大值的最小)
题目&分析: 思路: Floyd变形(见上述紫书分析),根据题目要求对应的改变判断条件来解题. 代码: #include <bits/stdc++.h> #define inf 0 ...
- Java垃圾回收是如何工作的?
本教程是为了理解基本的Java垃圾回收以及它是如何工作的.这是垃圾回收教程系列的第二部分.希望你已经读过了第一部分:<Java 垃圾回收介绍>. Java 垃圾回收是一项自动化的过程,用来 ...
- python正则表达式的好文章(转)
http://www.cnblogs.com/huxi/archive/2010/07/04/1771073.html https://blog.csdn.net/shw800/article/det ...
- L2-006. 树的遍历(不建树)
L2-006. 树的遍历 给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出一个正整数N(<=30),是二叉树中结点 ...
- Vue如何tab切换高亮最简易方法
以往我们实现tab切换高亮通常是循环遍历先把所有的字体颜色改变为默认样式,再点亮当前点击的选项,而我们在vue框架中实现tab切换高亮显示并不需要如此,只需要将当前点击选项的index传入给一个变量, ...
- Mongodb学习总结(2)——MongoDB与MySQL区别及其使用场景对比
对于只有SQL背景的人来说,想要深入研究NoSQL似乎是一个艰巨的任务,MySQL与MongoDB都是开源常用数据库,但是MySQL是传统的关系型数据库,MongoDB则是非关系型数据库,也叫文档型数 ...
- poj 2404 中国邮递员问题 欧拉回路判定+状压dp
/* 状压dp 邮递员问题:求经过任意点出发经过每一条边一次并回到原点. 解法:1.如果是欧拉回路那么就是所有的边的总和. 2.一般的解法,找出所有的奇度顶点,任意两个顶点匹配,即最小完美匹配,可用状 ...
- -sql语句练习50题(Mysql学习练习版)
–1.学生表 Student(s_id,s_name,s_birth,s_sex) –学生编号,学生姓名, 出生年月,学生性别 –2.课程表 Course(c_id,c_name,t_id) – –课 ...