Running Median

Time Limit: 1 Sec  Memory Limit: 256 MB

题目连接

  http://acm.hdu.edu.cn/showproblem.php?pid=3282

Description

For this problem, you will write a program that reads in a sequence of 32-bit signed integers. After each odd-indexed value is read, output the median (middle value) of the elements received so far.

Input

The first line of input contains a single integer P, (1 ≤ P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by an odd decimal integer M, (1 ≤ M ≤ 9999), giving the total number of signed integers to be processed.
The remaining line(s) in the dataset consists of the values, 10 per line, separated by a single space.
The last line in the dataset may contain less than 10 values.

Output

For each data set the first line of output contains the data set number, a single space and the number of medians output (which should be one-half the number of input values plus one). The output medians will be on the following lines, 10 per line separated by a single space. The last line may have less than 10 elements, but at least 1 element. There should be no blank lines in the output.

Sample Input

3
1 9
1 2 3 4 5 6 7 8 9
2 9
9 8 7 6 5 4 3 2 1
3 23
23 41 13 22 -3 24 -31 -11 -8 -7
3 5 103 211 -311 -45 -67 -73 -81 -99
-33 24 56

Sample Output

1 5 1 2 3 4 5 2 5 9 8 7 6 5 3 12 23 23 22 22 13 3 5 5 3 -3 -7 -3

HINT

题意

给你n个数,每次插入一个数,当插入数的数量为奇数的时候,我们就输出中位数

题解:

这道题要求动态求中位数,但是数据范围太小了,于是我们直接暴力搞就好了

事先排序,然后每次都扫一遍就行了……

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
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 100005
#define mod 10007
#define eps 1e-9
//const int inf=0x7fffffff;   //无限大
const int inf=0x3f3f3f3f;
/**/
//**************************************************************************************
inline ll read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}
struct node
{int x,y;
};
node a[maxn];
bool cmp(node b,node c)
{return b.x<c.x;
}
int main()
{int t=read();for(int cas=1;cas<=t;cas++){vector<int> ans;int n=read(),m=read();for(int i=0;i<m;i++)a[i].x=read(),a[i].y=i+1;sort(a,a+m,cmp);for(int i=0;i<m;i+=2){int flag=0;for(int j=0;j<m;j++){if(a[j].y<=i+1)flag++;if(flag==(i+2)/2){ans.push_back(a[j].x);break;}}}printf("%d %d",cas,ans.size());for(int i=0;i<ans.size();i++){if((i)%10==0)printf("\n");if(i%10==0)printf("%d",ans[i]);elseprintf(" %d",ans[i]);}printf("\n");}
}

转载于:https://www.cnblogs.com/qscqesze/p/4386718.html

HDU 3282 Running Median 动态中位数,可惜数据范围太小相关推荐

  1. 如何判断你的数据集是否适合使用深度学习模型?如果数据量太小有什么解决办法?

    如何判断你的数据集是否适合使用深度学习模型?如果数据量太小有什么解决办法? deep learning is a data hungry problem 数据集太小,数据样本不足时,深度学习相对其它机 ...

  2. vue-axios下载文件流blob,ie下载报传递给系统调用的数据区域太小.ie文件流下载报错;文件下载失败将blob的错误信息转换成json格式

    本次下载是后台文件流传输,前端下载,前端将拿到的下载id和名称downloadName传递给下载方法:如果是多个下载,可以采用数组for循环 情景描述: 1.如果符合导出条件, 后端直接返回数据流,如 ...

  3. 传递给系统调用的数据区域太小。 (异常来自 HRESULT:0x8007007A)

    传递给系统调用的数据区域太小. (异常来自 HRESULT:0x8007007A) 参考文章: (1)传递给系统调用的数据区域太小. (异常来自 HRESULT:0x8007007A) (2)http ...

  4. win10系统右键新建菜单里office报错0x8007007A:传递给系统调用的数据区域太小。

    问题描述: 鼠标右键新建word.excel等office文件时,提示错误:0x8007007A:传递给系统调用的数据区域太小.但原有office文件可正常使用(本人电脑是thinkpad,offic ...

  5. NVIDIA控制面板打开报错,提示nvcplui.exe应用程序错误并显示传递给系统调用的数据区域太小

    打开NVIDIA控制面板时提示错误,提示nvcplui.exe应用程序错误并显示传递给系统调用的数据区域太小 解决方法:打开报错提示中程序所在路径 我电脑对应路径如下图所示 在电脑中进入对应路径,可能 ...

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

    题目链接:点击查看 题目大意:给出n个数,依次读入一个整数序列,每当已经读入的整数个数为奇数时,输出已读入的整数构成的序列的中位数 题目分析:动态维护中位数,我们可以直接用两个二叉堆来维护,一个是小顶 ...

  7. poj3784 Running Median查找中位数

    参考http://blog.csdn.net/sdfzyhx/article/details/52735387 凡是关于排序,可以考虑优先队列. #include<cstdio> #inc ...

  8. 【POJ3784】Running Median(中位数,对顶堆)

    description 输入M个数,当已输入的个数为奇数个时输出此时的中位数. 一共有M/2+1个中位数要输出,每一行10个. solution 维护两个优先队列. 大根堆q1维护比当前中位数小的元素 ...

  9. ie传递给系统调用的数据区域太小_内存区域与内存溢出异常

    自动内存管理机制 运行时数据区:Java虚拟机定义了在程序执行期间使用的各种运行时数据区域.其中一些数据区域是在Java虚拟机启动时创建的,仅在Java虚拟机退出时销毁.其他数据区域是每个线程所占的空 ...

最新文章

  1. postfix邮件安装配置文档
  2. MySql之触发器【过度变量 new old】
  3. 只需2.5W功耗,就能达到5TOPS算力!地平线新一代AIoT芯片「旭日3」发布
  4. Android(Xamarin)之旅(三)
  5. android手机存储大小设置在哪里看,Android 最新获取手机内置存储大小,SD卡存储空间大小方法...
  6. PHP Ajax 跨域问题最佳解决方案
  7. Keras版GCN源码解析
  8. 安装Centos7时提示 /dev/root does not exits
  9. ERP仓库管理系统主要功能
  10. 华为mate40和vivox50pro+哪个好
  11. 解决打开xml文件没有代码
  12. 李沐精读论文:MAE 《Masked Autoencoders Are Scalable Vision Learners》
  13. Java字符串分割方法split()的功能以及使用方法的详细介绍!
  14. Diary(一)——登录功能(上)
  15. android 放大镜 Magnifier 简单实现
  16. C++: 随机生成一个 RxC 列联表(附完整源码)
  17. 离职无须迁集体户口 新生儿也能落集体户口
  18. 谁能治好抖音们的“版权病”?
  19. 云服务器部署nginx
  20. 周鸿祎推动了中国互联网的进步

热门文章

  1. [YTU]_2920( Shape系列-6)
  2. numel--矩阵的元素个数
  3. ios 如何在cell中去掉_经典问题:代码中如何去掉烦人的“!=nullquot;判空语句
  4. 指针学习笔记(更新中)
  5. 矩阵二范数(norm)
  6. gx works怎么写入from指令_FANUC PMC 指令和应用
  7. Terminal(终端) 在 OS X下如何快速调用
  8. 自定义UICollectionView
  9. MySoft.Data从入门到精通系列(五)【数据更新】
  10. 解决UnicodeEncodeError: 'ascii' codec can't encode