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. 【内核】linux内核启动流程详细分析【转】

    转自:http://www.cnblogs.com/lcw/p/3337937.html Linux内核启动流程 arch/arm/kernel/head-armv.S 该文件是内核最先执行的一个文件 ...

  2. Flask小demo---代码统计系统

    功能要求: 管理员登录 # 第一天 班级管理 # 第一天 学生管理 # 第一天 学生登录 上传代码(zip文件和.py文件) 查看个人提交记录列表 highchar统计 学生列表上方使用柱状图展示现班 ...

  3. Owin WebApi版本控制

    public class WebApiControllerSelector : IHttpControllerSelector { private const string NamespaceKey ...

  4. python随笔(三)

    在对字符串的操作中,s[::-1]表示将字符串逆序输出. 字符串本身不能改变(管理者而非所有者) 列表的内容是可以改变的,且列表的内容可以不仅仅是字符串.对于一个列表,注意b=a和b=a[:]的区别. ...

  5. 编写组件TComponent published $M+ 问题

    报错如下: PUBLISHED caused RTTI ($M+) to be added to type 修改成下面这样之后: 解决问题 方法: 来自:http://www.cnblogs.com/ ...

  6. HDU 2609 How many(最小表示+set)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2609 题目大意: 题目大意有n个有01组成的字符串,每个字符串都代表一个项链,那么该字符串就是一个环状 ...

  7. centos7 PDI(Kettle)安装

    kettle介绍 PDI(Kettle)是一种开源的 ETL 解决方案,书中介绍了如何使用PDI来实现数据的剖析.清洗.校验.抽取.转换.加载等各类常见的ETL类工作. 除了ODS/DW类比较大型的应 ...

  8. GUC-6 Callable 接口

    import java.util.concurrent.Callable; import java.util.concurrent.ExecutionException; import java.ut ...

  9. OS X 配置 Apache

    1.去掉javascript:void(0);Include /private/etc/apache2/extra/httpd-vhosts.con的注释,以启用虚拟主机: 2.在<Direct ...

  10. day6 ConfigParser模块 yaml模块

        yaml模块: python可以处理yaml文件,yaml文件安装的方法为:$ pip3 install pyyaml    configparser模块,用来处理文件的模块,可以实现文件的增 ...