51nod平均数
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long int64;
const double eps=1e-;
const int maxn=;
int n,a[maxn],sum[maxn],pos[maxn];
double l,r,mid,ans,b[maxn],s[maxn],list[maxn];
int64 k;
int lowbit(int x){return x&(-x);}
void insert(int x){for (int i=x;i<=n+;i+=lowbit(i)) sum[i]++;}
int64 query(int x){
int64 temp=;
for (int i=x;i;i-=lowbit(i)) temp+=sum[i];
return temp;
}
bool judge(double num){
memset(sum,,sizeof(sum)); b[]=;
for (int i=;i<=n;i++) b[i]=a[i]-num;
for (int i=;i<=n;i++) s[i]=s[i-]+b[i],list[i]=s[i];
list[n+]=; sort(list+,list+n+);
for (int i=;i<=n;i++) pos[i]=lower_bound(list+,list+n+,s[i])-list;
pos[]=lower_bound(list+,list+n+,)-list;
int64 tot=;
insert(pos[]);
for (int i=;i<=n;i++) tot+=query(pos[i]),insert(pos[i]);
return tot>=k;
}
int main(){
scanf("%d%lld",&n,&k);
for (int i=;i<=n;i++) scanf("%d",&a[i]);
l=1.0,r=100000.0;
while (l+eps<r){
mid=(l+r)/2.0;
if (judge(mid)) l=mid;
else r=mid;
}
printf("%.4lf\n",l);
return ;
}
题目大意:
LYK有一个长度为n的序列a。
51nod平均数的更多相关文章
- 51nod 平均数(马拉松14)
平均数 alpq654321 (命题人) 基准时间限制:4 秒 空间限制:131072 KB 分值: 80 LYK有一个长度为n的序列a. 他最近在研究平均数. 他甚至想知道所有区间的平均数,但是 ...
- 51nod 平均数(二分+树状数组)
题目链接: 平均数 基准时间限制:4 秒 空间限制:131072 KB 分值: 80 LYK有一个长度为n的序列a. 他最近在研究平均数. 他甚至想知道所有区间的平均数,但是区间数目实在太多了. 为了 ...
- 51nod 1682 中位数计数
1682 中位数计数基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 中位数定义为所有值从小到大排序后排在正中间的那个数,如果值有偶数个,通常取最中间的两个数值的平均 ...
- 51nod 1785 数据流中的算法 | STL的应用
51nod 1785 数据流中的算法 题面 动态求平均数.方差.中位数. 题解 这道题的坑: 平均数在答案中是向下取整输出并在后面添加".00" 方差:平方的平均数减去平均数的平方 ...
- 51nod 1785 数据流中的算法 (方差计算公式)
1785 数据流中的算法 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 51nod近日上线了用户满意度检测工具,使用高级人工智能算法,通过用户访问时间.鼠 ...
- 【51Nod 1244】莫比乌斯函数之和
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 模板题... 杜教筛和基于质因子分解的筛法都写了一下模板. 杜教筛 ...
- 51Nod 1268 和为K的组合
51Nod 1268 和为K的组合 1268 和为K的组合 基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 给出N个正整数组成的数组A,求能否从中选出若干个,使 ...
- 51Nod 1428 活动安排问题
51Nod 1428 活动安排问题 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1428 1428 活 ...
- 51Nod 1278 相离的圆
51Nod 1278 相离的圆 Link: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1278 1278 相离的圆 基 ...
随机推荐
- 02传智_jbpm与OA项目_部门模块
部门模块:具有增删改查(部门)的功能. Dao层的实现: 1,定义一个DepartmentDao.java. 定义基本的数据库操作.
- 从浏览器输入url到页面加载完成都发生了什么
一个http请求的过程 简要介绍一下一个http请求的网络传输过程: DNS Lookup先获得URL对应的IP地址 Socket Connect浏览器和服务器建立TCP连接 Send Request ...
- Android项目,从web上取下汉字,中文部分乱码
Android项目,从web上取下汉字,中文部分乱码. 常见问题,搜索一下,网上有很多办法解决.如果还没有试过这个办法,可以尝试一下. BufferedReader in = new Buffered ...
- [LINK]OpenResty
http://openresty.org/ http://www.tuicool.com/articles/M3yI3y http://www.oschina.net/question/28_6046 ...
- [资料]mysql实现地理位置搜索
mysql实现地理位置搜索 使用mysql来实现lbs(地理位置服务)功能 Mysql 地区经纬度 查询
- 硬盘安装win2003
1.将安装文件放到D盘或E盘,自己指定 2.用U盘或者光盘启动,进入DOS或WINPE吧,转到刚才指定的目录下,运行 winnt32 /syspart:c/marklocalsource/tempdr ...
- android错误之MediaPlayer用法的Media Player called in state *,androidmediaplayer
用到Media Player,遇到几个问题,记一下 用法就不说了,使用的时候最好参考一下mediaPlayer的这张图 第一个错误是Media Player called in state 8 这个是 ...
- android之自定义广播
布局文件 点击按钮发送广播 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...
- myeclipse加入JavaEE
1. 2. 3. 4.
- 线性表的链式存储C语言版
#include <stdio.h> #include <malloc.h> #define N 10 typedef struct Node { int data; stru ...