6127:Largest Average
#include<bits/stdc++.h>
using namespace std;
int a[100001];
double ave[100001];
struct student{
int i;
double ave;
};
student stu[100001]; bool cmp(const student &s1,const student &s2){
if(s1.ave==s2.ave){
return s1.i<s2.i;
}else{
return s1.ave>s2.ave;
}
} int main(){
priority_queue<int,vector<int>,greater<int> > q;
int n;
while(cin>>n){
memset(stu,0,sizeof(student)*n);
memset(a,0,sizeof(a));
memset(ave,0,sizeof(ave));
for(int i=0;i<n;++i){
scanf("%d",&a[i]);
}
double s=0;
for(int i=n-1;i>0;i--){
if(i!=n-1){
if(a[i]<q.top()){ //如果这个数比队列中最小的值还小,算平均值的时候先没放进队列
int ss=q.size();
ave[i]=s*1.0/ss;
stu[i].ave=ave[i];
stu[i].i=i;
q.push(a[i]); //最后再放进队列
}else{ //如果这个数比队列中最小的值大
q.push(a[i]); //把这个数放进队列
int x=q.top();
q.pop(); //把队列中最小的值弹出
int ss=q.size();
ave[i]=(s+a[i]-x)*1.0/ss; //算出平均值
stu[i].ave=ave[i];
stu[i].i=i;
q.push(x); //最后把最小的值压回去队列
}
}else{
q.push(a[i]);
ave[i]=a[i];
stu[i].ave=ave[i];
stu[i].i=i;
}
s+=a[i];
//printf("%d %.2f\n",stu[i].i,stu[i].ave);
}
sort(stu,stu+n,cmp);
cout<<stu[0].i;
for(int i=1;i<n;++i){
if(stu[i].ave==stu[0].ave&&stu[i].i<=n-2){
cout<<" "<<stu[i].i;
}else{
break;
}
}
while(!q.empty()){
q.pop();
}
cout<<endl;
}
}
6127:Largest Average的更多相关文章
- LeetCode之“排序”:Largest Number
题目链接 题目要求: Given a list of non negative integers, arrange them such that they form the largest numbe ...
- Leetcode:Largest Number详细题解
题目 Given a list of non negative integers, arrange them such that they form the largest number. For e ...
- LeetCode第[84]题(Java):Largest Rectangle in Histogram(最大的矩形柱状图)
题目:最大的矩形柱状图 难度:hard 题目内容: Given n non-negative integers representing the histogram's bar height wher ...
- LeetCode OJ:Largest Number(最大数字)
Given a list of non negative integers, arrange them such that they form the largest number. For exam ...
- HDU 5461:Largest Point
Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- HDU1506: Largest Rectangle in a Histogram(最大子矩阵,好题动态优化左右边界)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1506 刚开始没考虑时间复杂度,直接敲了,直接tle了,之后没有思路,然后看题解,看见大神写的优化非常棒. ...
- POJ2559:Largest Rectangle in a Histogram
浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:http://poj.org/problem?id=2559 贪心的想,最大的子矩阵顶部 ...
- AtCoder Grand Contest 009 E:Eternal Average
题目传送门:https://agc009.contest.atcoder.jp/tasks/agc009_e 题目翻译 纸上写了\(N\)个\(1\)和\(M\)个\(0\),你每次可以选择\(k\) ...
- AGC009:Eternal Average
传送门 好神啊 直接考虑一棵 \(n+m\) 个叶子的 \(k\) 叉树,根结点权值为 \(\sum_{i\in m}(\frac{1}{k})^{deep_i}\) 对于一个 \(deep\) 的序 ...
随机推荐
- Apache伪静态(Rewrite).htaccess文件详解
Htaccess(超文本访问)是一个简单的配置文件,它允许设计师,开发者和程序员通过它来改变Apache Web服务器的配置.这些功能包括用户重定向.URL重写(url rewrite,国内很多称为伪 ...
- Akka Typed 官方文档之随手记
️ 引言 近两年,一直在折腾用FP与OO共存的编程语言Scala,采取以函数式编程为主的方式,结合TDD和BDD的手段,采用Domain Driven Design的方法学,去构造DDDD应用(Dom ...
- Github美化 添加徽章
Github美化 添加徽章 0. 前言 1. 准备 2. 开始 a. 打开shields.io b.制作静态徽章 c.制作动态徽章 d. 结果 3.额外 0. 前言 之前看见很多大项目都有很多勋章,比 ...
- Ubuntu_Gedit配置
Ubuntu_Gedit配置 为了换Ubuntu的时候能够更加方便,不用再用手重新打一遍代码,丢几个Gedit配置-- External Tools gdb compile (F2) #!/bin/s ...
- 十三:SQL注入之MYSQL注入
MYSQL注入中首先要明确当前注入点权限,高权限注入时有更多的攻击手法,有的能直接进行getshell操作,其中也会遇到很多的阻碍,相关防御手法也要明确,所谓知己知彼,百战不殆.作为安全开发工作者,攻 ...
- 简单解析一下 Mybatis 常用的几个配置
目录 核心配置文件 环境配置(environments) 属性(properties) 类型别名(typeAliases) 映射器(mappers) Mybatis 参考:https://mybati ...
- nginx启动失败(bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket...permissions)
nginx启动失败 nginx启动失败(bind() to 0.0.0.0:80 failed (10013: An attempt was made to access a socket in a ...
- zabbix 监控的数据
/usr/local/zabbix/bin/zabbix_sender --zabbix-server 192.168.1.10 --port 10051 --input-file /var/log/ ...
- 【Linux】服务器识别ntfs移动磁盘方法
Linux服务器无法识别ntfs磁盘 如果想识别的话,需要安装一个包ntfs-3g 安装好后,将移动磁盘插入到服务器的usb口中 新建一个目录,将磁盘挂载在新建的目录上 挂载命令如下: mount - ...
- leetcode 1240. 铺瓷砖(回溯,DFS)
题目链接 https://leetcode-cn.com/problems/tiling-a-rectangle-with-the-fewest-squares/ 题意: 用尽可能少的正方形瓷砖来铺地 ...