ural 1306. Sequence Median
1306. Sequence Median
Memory limit: 1 MB
Language limit: C, C++, Pascal
Input
Output
Sample
input | output |
---|---|
4 |
4.5 |
#include <cstdio>
#include <queue>
#include <iostream>
using namespace std;
inline void SetIO(string Name)
{
string Input = Name+".in",
Output = Name+".out";
freopen(Input.c_str(), "r", stdin),
freopen(Output.c_str(), "w", stdout);
} int n, Arr[ / + ]; inline void Input()
{
scanf("%d", &n);
} inline void Solve()
{
for(int i = ; i < n / + ; i++) scanf("%d", &Arr[i]);
make_heap(Arr, Arr + n / + );
for(int i = n / + ; i < n; i++)
{
scanf("%d", &Arr[n / + ]);
push_heap(Arr, Arr + n / + );
pop_heap(Arr, Arr + n / + );
}
if(n & ) printf("%.1lf\n",1.0 * Arr[]);
else
{
unsigned int x = Arr[];
pop_heap(Arr, Arr + n / + );
unsigned int y = Arr[];
printf("%.1lf\n", 1.0 * (x + y) / 2.0);
}
} int main()
{
#ifndef ONLINE_JUDGE
SetIO("G");
#endif
Input();
Solve();
return ;
}
ural 1306. Sequence Median的更多相关文章
- URAL 1306 Sequence Median(优先队列)
题意:求一串数字里的中位数.内存为1M.每个数范围是0到2的31次方-1. 思路:很容易想到把数字全部读入,然后排序,但是会超内存.用计数排序但是数又太大.由于我们只需要第n/2.n/2+1大(n为偶 ...
- URAL 1306 - Sequence Median 小内存求中位数
[题意]给出n(1~250000)个数(int以内),求中位数 [题解]一开始直接sort,发现MLE,才发现内存限制1024k,那么就不能开int[250000]的数组了(4*250000=1,00 ...
- 1306.Sequence Median(堆排序)
1306 URAL真是没水题 以为简单的排序就好了 ME 内存限制很紧 堆排序 或者 STL 用堆排序做的 正好复习一下 都忘了 #include <iostream> #include ...
- poj 2623 Sequence Median 堆的灵活运用
I - Sequence Median Time Limit:1000MS Memory Limit:1024KB 64bit IO Format:%I64d & %I64u ...
- Ural 1248 Sequence Sum 题解
目录 Ural 1248 Sequence Sum 题解 题意 题解 程序 Ural 1248 Sequence Sum 题解 题意 给定\(n\)个用科学计数法表示的实数\((10^{-100}\s ...
- (poj)Sequence Median
Description Given a sequence of N nonnegative integers. Let's define the median of such sequence. If ...
- URAL1306 Sequence Median(卡内存神题)
给出n个数,n<=250000,求这n个数的中位数,内存限制1mb 卡内存的神题,用数组存下来刚好1mb,再加上执行时消耗内存.立即爆. 因此我们用优先队列存储一半的数. 网上的某些代码,用pr ...
- 二分法&三分法
ural History Exam 二分 #include <iostream> #include <cstdlib> using namespace std; //二分 ...
- 投入OJ的怀抱~~~~~~~~~~
OpenJudge C20182024 信箱(1) 账号 修改设定 退出小组 管理员 frank 林舒 Dzx someone 李文新 公告 11-05 程序设计与算法(大学先修课) 成员(61910 ...
随机推荐
- samba服务搭建及管理
关闭防火墙 # /etc/init.d/iptables stop # chkconfig --level iptables off 关闭SELINUX # vim /etc/sysconfig/se ...
- c# 继承,多态,new /overrid 区别, 引用父类的方法
好久没碰c#了,偶尔需要制作点小工具.为了一个灵活的架构设计,需要对继承/多态有比较深刻的理解. 不料忘得差不多了,好吧,再来回忆下.直接上代码了,如下: using System; using Sy ...
- 要“jquery”ScriptResourceMapping。请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping。”的解决办法。
1.在网站根目录下新建一scripts文件夹,向里边添加jquery-1.7.2.min.js和jquery-1.7.2.js(可根据自己需要使用不同的版本), 2.在根目录下添加全局应用程 ...
- VIM替换、截取及追加操作
参考: http://blog.csdn.net/love__coder/article/details/6739670 http://blog.csdn.net/love__coder/articl ...
- iOS的 context 和Android 中的 canvas
ios 想要绘图,要用到CGContextRef类.最基本的用法是在- (void)drawRect:(CGRect)rect 函数中绘制. Android 中要用到Canvas类.最基本的用法是在 ...
- 【JAVA、C++】LeetCode 017 Letter Combinations of a Phone Number
Given a digit string, return all possible letter combinations that the number could represent. A map ...
- Base Filtering Engine 拒绝访问解法
基本筛选引擎(BFE)是一种管理防火墙和 Internet 协议安全(IPsec)策略以及实施用户模式筛选的服务.停止或禁用 BFE 服务将大大降低系统的安全.还将造成 IPsec 管理和防火墙应用程 ...
- 为什么内联函数,构造函数,静态成员函数不能为virtual函数
http://blog.csdn.net/freeboy1015/article/details/7635012 为什么内联函数,构造函数,静态成员函数不能为virtual函数? 1> 内联函数 ...
- Android之ViewDragHelper
在自定义ViewGroup中,很多效果都包含用户手指去拖动其内部的某个View(eg:侧滑菜单等),针对具体的需要去写好onInterceptTouchEvent和onTouchEvent这两个方法是 ...
- rsync实时同步文件
http://rsync.samba.org/download.html [root@v01 src]# yum install git [root@v01 src]# git clone git:/ ...