I - Sequence Median

Time Limit:1000MS     Memory Limit:1024KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

Given a sequence of N nonnegative integers. Let's define the median of such sequence. If N is odd the median is the element with stands in the middle of the sequence after it is sorted. One may notice that in this case the median has position ( N+1)/2 in sorted sequence if sequence elements are numbered starting with 1. If N is even then the median is the semi-sum of the two "middle" elements of sorted sequence. I.e. semi-sum of the elements in positions N/2 and ( N/2)+1 of sorted sequence. But original sequence might be unsorted.
Your task is to write program to find the median of given sequence.

Input

The first line of input contains the only integer number N — the length of the sequence. Sequence itself follows in subsequent lines, one number in a line. The length of the sequence lies in the range from 1 to 250000. Each element of the sequence is a positive integer not greater than 2 31−1 inclusive.

Output

You should print the value of the median with exactly one digit after decimal point.

Sample Input

input output
4
3
6
4
5
4.5

这道题 你会发现存不下,只能存一半

然后瞎搞搞,就出来了

#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100001
const int inf=0x7fffffff; //无限大
priority_queue<unsigned int> q;
int main()
{
int n;
while(cin>>n)
{
while(!q.empty())
q.pop();
unsigned int x;
int kill=n/+;
unsigned int fuck;
for(int i=;i<kill;i++)
{
cin>>x;
q.push(x);
}
for(int i=kill;i<n;i++)
{
cin>>x;
fuck=q.top();
if(x<fuck)
{
q.pop();
q.push(x);
}
}
if(n%==)
{
unsigned int a=q.top();
q.pop();
unsigned int b=q.top();
printf("%.1lf\n",(a+b)/2.0);
}
else
{
unsigned int a=q.top();
printf("%.1lf\n",a*1.0);
}
}
return ;
}

poj 2623 Sequence Median 堆的灵活运用的更多相关文章

  1. (poj)Sequence Median

    Description Given a sequence of N nonnegative integers. Let's define the median of such sequence. If ...

  2. POJ 2442 Sequence【堆】

    题目链接:http://poj.org/problem?id=2442 题目大意:给出一个m*n的矩阵,从每一行中取出一个数相加.能得到n^m个不同的结果.要求输出当中前n项. 建立一个以n元数组为底 ...

  3. ural 1306. Sequence Median

    1306. Sequence Median Time limit: 1.0 secondMemory limit: 1 MBLanguage limit: C, C++, Pascal Given a ...

  4. [POJ 3581]Sequence

    [POJ 3581]Sequence 标签: 后缀数组 题目链接 题意 给你一串序列\(A_i\),保证对于$ \forall i \in [2,n],都有A_1 >A_i$. 现在需要把这个序 ...

  5. Running Median POJ - 3784 (对顶堆/优先队列 | 链表)

    For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After ...

  6. POJ 2442 - Sequence - [小顶堆][优先队列]

    题目链接:http://poj.org/problem?id=2442 Time Limit: 6000MS Memory Limit: 65536K Description Given m sequ ...

  7. POJ 2442 Sequence(堆的使用练习)

    题目地址:id=2442">POJ 2442 真心没想到这题的思路. .原来是从第一行逐步向下加,每次都仅仅保存前n小的数.顺便练习了下堆.. 只是感觉堆的这样的使用方法用的不太多啊. ...

  8. POJ 2442 Sequence堆 优先队列

    题目描述 给定m个序列,每个序列包含n个非负整数.现在我们可以从每个序列中选择一个数字以形成一个具有m个整数的序列.显然,我们可以得到n ^ m种这种序列.然后,我们可以计算每个序列中的数字总和,并获 ...

  9. POJ 3784 Running Median(动态维护中位数)

    Description For this problem, you will write a program that reads in a sequence of 32-bit signed int ...

随机推荐

  1. 一步一步搭建 oracle 11gR2 rac+dg之grid安装(四)【转】

    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之grid安装 (四) 转自 一步一步搭建 oracle 11gR2 rac+d ...

  2. 一步一步搭建oracle 11gR2 rac+dg之database安装(五)【转】

    一步一步在RHEL6.5+VMware Workstation 10上搭建 oracle 11gR2 rac + dg 之database安装 (五)   转自 一步一步搭建oracle 11gR2 ...

  3. CKEDITOR的内容js转码,C#控制器解码接收

    <script type="text/javascript" src="<%=Url.Content("~/Resource/ckeditor/ck ...

  4. oracle11g 创建id自增长监听器的步骤与问题

    首先,我们通过sql/plus先建个TEST表 sql语句: CTEATE TABLE TEST( ID NUMBER, NAME VARCHAR2(20), PRIMARY KEY(ID) ); 通 ...

  5. JAVA随笔(三)

    私有是针对类的,而不是对象. static 函数,其实是类函数.之前一直不太理解每个类中的static main是什么意思,为什么main中不能直接调用非静态的变量:因为main是 类函数,不是属于某 ...

  6. php 的swoole 和websocket 连接wss

    1. 下载证书 $serv = new swoole_server('0.0.0.0', 9501, SWOOLE_PROCESS, SWOOLE_SOCK_TCP | SWOOLE_SSL); $s ...

  7. ZOJ 3781 Paint the Grid Reloaded(DFS连通块缩点+BFS求最短路)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5268 题目大意:字符一样并且相邻的即为连通.每次可翻转一个连通块X( ...

  8. HDU 3374 String Problem(KMP+最大(最小)表示)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3374 题目大意:给出一个字符串,依次左移一个单位形成一堆字符串,求其字典序最小和最大的字符串需要左移多 ...

  9. VS Code折腾记 - (1)扯淡

    题外话 距离上篇介绍VSCode的文章已经过去四十多天,已经在正式项目作为主力开发工具了. 社区的发展非常快速,更新迭代够快,功能基本已经满足我所需了: 这个系列教程基于最新的vs code 1.8. ...

  10. JavaScript工程师都应懂的33个概念

    最近福利发的有点多啊,各种硬干货,小伙伴们是不是觉得很爽啊.Github真的蕴含着各种各样的宝藏,难怪各个大厂也都纷纷贡献自己的代码到Github上. 所以各种干货还是会源源不断的po给大家,觉得有帮 ...