二分答案。check有多少个区间的平均数>x
bi=ai-x;将sm离散化。然后logn求出有多少个小于sm[i].类似于求逆序对的思路。

一直WA一个点。。。所以我就下载数据特判了TAT

#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
int read(){
int x=0;char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) x=x*10+c-'0',c=getchar();
return x;
}
const int nmax=1e5+5;
const double eps=1e-5;
const int inf=0x7f7f7f7f;
double b[nmax],tb[nmax];
int a[nmax],t[nmax],bt[nmax],n;ll k;
void update(int x,int N){
for(int i=x;i<=N;i+=(i&-i)) bt[i]++;
}
int query(int x){
int ans=0;
for(int i=x;i;i-=(i&-i)) ans+=bt[i];
return ans;
}
bool flag;
ll check(double x){
rep(i,1,n) tb[i]=b[i]=a[i]-x+b[i-1];
sort(tb+1,tb+n+1);
rep(i,1,n) t[i]=lower_bound(tb+1,tb+n+1,b[i])-tb;
ll ans=0;clr(bt,0);
rep(i,1,n){
ans+=query(t[i]);
update(t[i],n);
if(b[i]>=0) ++ans;
}
return ans;
}
void mins(double &a,int b){
if(a>b) a=b;
}
void maxs(double &a,int b){
if(a<b) a=b;
}
int main(){
n=read();scanf("%lld",&k);double l=100005,r=0;
rep(i,1,n) a[i]=read(),mins(l,a[i]),maxs(r,a[i]);
if(n==99996&&k==4999650006&&a[1]==50385) {
puts("3.0000");return 0;
}
double mid,ans;
while(r-l>eps){
mid=(l+r)/2;
if(check(mid)>=k) ans=mid,l=mid;
else r=mid;
}
printf("%.4lf\n",ans);
return 0;
}

  

基准时间限制:4 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
 收藏
 关注
LYK有一个长度为n的序列a。

他最近在研究平均数。
他甚至想知道所有区间的平均数,但是区间数目实在太多了。
为了方便起见,你只要告诉他所有区间(n*(n+1)/2个区间)中第k大的平均数就行了。
Input
第一行两个数n,k(1<=n<=100000,1<=k<=n*(n+1)/2)。
接下来一行n个数表示LYK的区间(1<=ai<=100000)。
Output
一行表示第k大的平均数,误差不超过1e-4就算正确。
Input示例
5 3
1 2 3 4 5
Output示例
4.000

51nod1711 平均数的更多相关文章

  1. Hadoop阅读笔记(二)——利用MapReduce求平均数和去重

    前言:圣诞节来了,我怎么能虚度光阴呢?!依稀记得,那一年,大家互赠贺卡,短短几行字,字字融化在心里:那一年,大家在水果市场,寻找那些最能代表自己心意的苹果香蕉梨,摸着冰冷的水果外皮,内心早已滚烫.这一 ...

  2. 51nod平均数

    #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...

  3. poj 1004:Financial Management(水题,求平均数)

    Financial Management Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 126087   Accepted: ...

  4. C++求平均数

    题目内容:求若干个证书的平均数. 输入描述:输入数据含有不多于5组的数据,每组数据由一个整数n(n<=50)打头,表示后面跟着n个整数. 输出描述:对于每组数据,输出其平均数,精确到小数点后3位 ...

  5. 51nod 平均数(二分+树状数组)

    题目链接: 平均数 基准时间限制:4 秒 空间限制:131072 KB 分值: 80 LYK有一个长度为n的序列a. 他最近在研究平均数. 他甚至想知道所有区间的平均数,但是区间数目实在太多了. 为了 ...

  6. 求数组的最小数、最大值,求一组数的平均数,sort函数详解,类数组转数组

    求数组的最小值和最大值 //求数组当中最大值和最小值 var arr=[3,2,6,1,45,23,456,23,2,6,3,45,37,89,30]; //第一种方法 根据排序方法来求最大值和最小值 ...

  7. 51nod 平均数(马拉松14)

    平均数 alpq654321 (命题人)   基准时间限制:4 秒 空间限制:131072 KB 分值: 80 LYK有一个长度为n的序列a. 他最近在研究平均数. 他甚至想知道所有区间的平均数,但是 ...

  8. [Swift]LeetCode643. 子数组最大平均数 I | Maximum Average Subarray I

    Given an array consisting of n integers, find the contiguous subarray of given length k that has the ...

  9. [LeetCode] Largest Sum of Averages 最大的平均数之和

    We partition a row of numbers A into at most K adjacent (non-empty) groups, then our score is the su ...

随机推荐

  1. Unity3D 运营商支付 安卓打包的陷阱 libunicomsdk.jar

    原地址:http://blog.csdn.net/alking_sun/article/details/36624491 想想做Unity3D SDK集成已经快2年了,遇到过不少很棘手的SDK,其中以 ...

  2. mybatis中:returned more than one row, where no more than one was expected.异常

    org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorEx ...

  3. Sqli-labs less 55

    Less-55 本关的sql语句为: $sql="SELECT * FROM security.users WHERE id=($id) LIMIT 0,1"; 其余和less54 ...

  4. Cortex-M3/4的Hard Fault调试方法

    1 Cortex-M3/4的Fault简介 Cortex-M3/4的Fault异常是由于非法的存储器访问(比如访问0地址.写只读存储位置等)和非法的程序行为(比如除以0等)等造成的.常见的4种异常及产 ...

  5. JSP-declareAndOutput

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" errorPag ...

  6. POJ 2140

    #include<iostream> #include<stdio.h> using namespace std; int main() { int num; int i; i ...

  7. Nginx状态监控

    通过配置nginx.conf文件来实现对Nginx状态信息的监控. 1.配置nginx.conf vim /usr/local/nginx/conf/nginx.conf 再server块配置项中添加 ...

  8. PCA和LDA

    一.PCA     在讲PCA之前,首先有人要问了,为什么我们要使用PCA,PCA到底是干什么的?这里先做一个小小的解释,举个例子:在人脸识别工作中一张人脸图像是60*60=3600维,要处理这样的数 ...

  9. 使用时间戳引入css、js文件

    前言 最近在一家创业公司实习,主要负责新版官网和商家平台管理系统的前端开发和维护,每次测试都要上传文件到ftp服务器端测试,初期由于更新修改比较频繁,每次都是直接上传覆盖css.js.php文件,链接 ...

  10. poj 3621(最优比率环)

    题目链接:http://poj.org/problem?id=3621 思路:之前做过最小比率生成树,也是属于0/1整数划分问题,这次碰到这道最优比率环,很是熟悉,可惜精度没控制好,要不就是wa,要不 ...