1306

URAL真是没水题 以为简单的排序就好了 ME  内存限制很紧 堆排序 或者 STL

用堆排序做的 正好复习一下 都忘了

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
using namespace std;
#define N 1250010
int a[N];
void adjust(int i,int n)
{
int j;
a[] = a[i];
j = *i;
while(j<=n)
{
if(j<n&&a[j+]>a[j])
j++;
if(a[]<a[j])
{
a[i] = a[j];
i = j;
j = *i;
}
else
break;
}
a[i] = a[];
}
int main()
{
int i,j,n,t,x;
scanf("%d",&n);
int k = n/+;
for(i = ; i <= k ; i++)
scanf("%d",&a[i]);
if(n==)
{
printf("%.1lf\n",(a[]/2.0+a[]/2.0));
return ;
}
for(i = k/ ; i>= ; i--)
adjust(i,k);
for(i = k+ ; i <= n ; i++)
{
scanf("%d",&x);
if(x<a[])
{
a[] = x;
adjust(,k);
}
}
for(i = k ; i > ; i--)
{
t = a[];
a[] = a[i];
a[i] = t;
adjust(,i-);
}
if(n%!=)
printf("%.1lf\n",1.0*a[k]);
else
printf("%.1lf\n",a[k-]/2.0+a[k]/2.0);
return ;
}

1306.Sequence Median(堆排序)的更多相关文章

  1. ural 1306. Sequence Median

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

  2. URAL 1306 Sequence Median(优先队列)

    题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...

  3. URAL 1306 - Sequence Median 小内存求中位数

    [题意]给出n(1~250000)个数(int以内),求中位数 [题解]一开始直接sort,发现MLE,才发现内存限制1024k,那么就不能开int[250000]的数组了(4*250000=1,00 ...

  4. poj 2623 Sequence Median 堆的灵活运用

    I - Sequence Median Time Limit:1000MS     Memory Limit:1024KB     64bit IO Format:%I64d & %I64u ...

  5. (poj)Sequence Median

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

  6. Sequence用堆排序

    Description Given m sequences, each contains n non-negative integer. Now we may select one number fr ...

  7. URAL1306 Sequence Median(卡内存神题)

    给出n个数,n<=250000,求这n个数的中位数,内存限制1mb 卡内存的神题,用数组存下来刚好1mb,再加上执行时消耗内存.立即爆. 因此我们用优先队列存储一半的数. 网上的某些代码,用pr ...

  8. 投入OJ的怀抱~~~~~~~~~~

    OpenJudge C20182024 信箱(1) 账号 修改设定 退出小组 管理员 frank 林舒 Dzx someone 李文新 公告 11-05 程序设计与算法(大学先修课) 成员(61910 ...

  9. PAT 1029 Median[求中位数][难]

    1029 Median(25 分) Given an increasing sequence S of N integers, the median is the number at the midd ...

随机推荐

  1. SQL动态更新表字段 传入字段可能为空

    小技巧: 项目组有修改产品的基本信息字段 但有时候传入的字段可能为空 也可能不为空  动态修改表中字段. USE [BetaProductMarket_DB] GO )) BEGIN DROP PRO ...

  2. 《WPF程序设计指南》读书笔记——第9章 路由输入事件

    1.使用路由事件 路由事件是一种可以针对元素树中的多个侦听器(而不是仅针对引发该事件的对象)调用处理程序的事件.通俗地说,路由事件会在可视树(逻辑树是其子集)上,上下routed,如果哪个节点上订阅了 ...

  3. WPF中的多点触摸事件

    UIElement在WPF4下添加了很多支持多点触摸的事件,通过它们可以在硬件支持的情况下处理多点触摸,以下通过代码来说明通过处理这些事件,我们可以做些什么: 一.触摸相关的多种事件,跟鼠标事件是对应 ...

  4. 1054. The Dominant Color (20)

    时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Behind the scenes in the compute ...

  5. 三类,23种设计模式,速记理解法!PHP

    一,创建型设计模式 1.FACTORY—追MM少不了请吃饭了,麦当劳的鸡翅和肯德基的鸡翅都是MM爱吃的东西,虽然口味有所不同,但不管你带MM去麦当劳或肯德基,只管向服务员说“来四个鸡翅”就行了.麦当劳 ...

  6. Oracle查看用户所在表空间

    查看当前用户所在表空间 select username,default_tablespace from user_users; 修改用户默认表空间 alter user 用户名 default tab ...

  7. 小小地预览HTML5

    程序示例 <!doctype html> <html> <head> <title>First </title> <meta char ...

  8. 写作技巧--Simile明喻

  9. secureCRT中文字符乱码

    1.远程linux机器.修改环境变量LANG.例如在~/.bash_profile里面添加 export LANG=zh_CN.UTF8 2.本地windows机器.修改SecureCRT的设置.找到 ...

  10. linux fork函数与vfork函数

    一.fork1. 调用方法#include <sys/types.h>#include <unistd.h> pid_t fork(void);正确返回:在父进程中返回子进程的 ...