Codeforces 380E Sereja and Dividing
题面
题解
有精度要求所以只用求几十次就差不多了
CODE
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAXN = 300005;
struct node {
int v, id;
inline bool operator <(const node &o)const {
return v < o.v || (v == o.v && id < o.id);
}
}p[MAXN];
int n, pre[MAXN], nxt[MAXN];
int main () {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &p[i].v), p[i].id = i, pre[i] = i-1, nxt[i] = i+1;
sort(p + 1, p + n + 1);
double ans = 0;
for(int i = 1; i <= n; ++i) {
double l = 0, r = 0, pw = 1;
int x = p[i].id, lp = x, rp = x;
for(int j = 1; j <= 50; ++j) {
pw /= 2;
if(lp) l += pw*(lp - pre[lp]), lp = pre[lp];
if(rp<=n) r += pw*(nxt[rp] - rp), rp = nxt[rp];
}
ans += 2*l*r*p[i].v;
nxt[pre[x]] = nxt[x];
pre[nxt[x]] = pre[x];
}
printf("%.15f\n", ans/n/n);
}
Codeforces 380E Sereja and Dividing的更多相关文章
- CodeForces 1249A --- Yet Another Dividing into Teams
[CodeForces 1249A --- Yet Another Dividing into Teams] Description You are a coach of a group consis ...
- codeforces 314E Sereja and Squares
discription Sereja painted n points on the plane, point number i (1 ≤ i ≤ n) has coordinates (i, 0). ...
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- codeforces 425C Sereja and Two Sequences(DP)
题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...
- codeforces B. Sereja and Stairs 解题报告
题目链接:http://codeforces.com/problemset/problem/381/B 题目意思:给定一个m个数的序列,需要从中组合出符合楼梯定义 a1 < a2 < .. ...
- codeforces A. Sereja and Bottles 解题报告
题目链接:http://codeforces.com/problemset/problem/315/A 题目意思:有n个soda bottles,随后给出这n个soda bottles的信息.已知第 ...
- Codeforces 380A - Sereja and Prefixes
原题地址:http://codeforces.com/problemset/problem/380/A 让期末考试整的好久没有写题, 放假之后由于生病也没怎么做,新年的第一场CF也不是那么在状态,只过 ...
- codeforces C. Sereja and Swaps
http://codeforces.com/contest/426/problem/C 题意:找出连续序列的和的最大值,可以允许交换k次任意位置的两个数. 思路:枚举区间,依次把区间内的比较小的数换成 ...
- CodeForces - 314C Sereja and Subsequences (树状数组+dp)
Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...
随机推荐
- kafka生产者消费者
import org.apache.kafka.clients.consumer.ConsumerRecord; import org.apache.kafka.clients.consumer.Co ...
- LeetCode 941. 有效的山脉数组(Valid Mountain Array)
941. 有效的山脉数组 941. Valid Mountain Array 题目描述 给定一个整数数组 A,如果它是有效的山脉数组就返回 true,否则返回 false. 让我们回顾一下,如果 A ...
- LeetCode 108. 将有序数组转换为二叉搜索树(Convert Sorted Array to Binary Search Tree) 14
108. 将有序数组转换为二叉搜索树 108. Convert Sorted Array to Binary Search Tree 题目描述 将一个按照升序排列的有序数组,转换为一棵高度平衡二叉搜索 ...
- Matlab R2017b 打开后一直显示“正在初始化”,导致无法运行命令
1. 前言 Matlab R2017b打开后一直显示"正在初始化",导致无法运行命令. 2. 解决方案 1. 找到并记录授权文件license_standalone.lic的路径. ...
- P1308(字符串类,处理字符串查找)
题目描述 一般的文本编辑器都有查找单词的功能,该功能可以快速定位特定单词在文章中的位置,有的还能统计出特定单词在文章中出现的次数. 现在,请你编程实现这一功能,具体要求是:给定一个单词,请你输出它在给 ...
- 数据结构-链式队列-C++
用链表搭建的栈与队列相对简单,队列的特点是先进先出,不啰嗦了,由于代码比较简单,相信光顾的人不会太多,下面直接贴代码. 头文件 #ifndef QUEUELI_H #define QUEUELI_H ...
- ubuntu 安装 Java 开发环境
可以使用命令 -jre-headless 或者使用: 本文链接:https://blog.csdn.net/sangewuxie/article/details/80958611 本人的ubunt ...
- 【转载】Intellij IDEA神器居然还有这些小技巧
概述Intellij IDEA真是越用越觉得它强大,它总是在我们写代码的时候,不时给我们来个小惊喜.出于对Intellij IDEA的喜爱,我决定写一个与其相关的专栏或者系列,把一些好用的Intell ...
- 使用File类、StreamRead和StreamWrite读写数据、以及Path类操作文件路径和Directory
1.File类的概念: File类,是一个静态类,主要是来提供一些函数库用的.静态实用类,提供了很多静态的方法,支持对文件的基本操作,包括创建,拷贝,移动,删除和 打开一个文件. File类方法的参量 ...
- 1.MVC基础-初识MVC,与WebForm比较
1.Net WebForm的开发模式