HDU 3282 Running Median 动态中位数,可惜数据范围太小
Running Median
Time Limit: 1 Sec Memory Limit: 256 MB
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=3282
Description
Input
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
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
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=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';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=;cas<=t;cas++)
{
vector<int> ans;
int n=read(),m=read();
for(int i=;i<m;i++)
a[i].x=read(),a[i].y=i+;
sort(a,a+m,cmp);
for(int i=;i<m;i+=)
{
int flag=;
for(int j=;j<m;j++)
{
if(a[j].y<=i+)
flag++;
if(flag==(i+)/)
{
ans.push_back(a[j].x);
break;
}
}
}
printf("%d %d",cas,ans.size());
for(int i=;i<ans.size();i++)
{
if((i)%==)
printf("\n");
if(i%==)
printf("%d",ans[i]);
else
printf(" %d",ans[i]); }
printf("\n"); }
}
HDU 3282 Running Median 动态中位数,可惜数据范围太小的更多相关文章
- hdu 3282 Running Median
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=3282 Running Median Description For this problem, you ...
- POJ 3784 Running Median (动态中位数)
题目链接:http://poj.org/problem?id=3784 题目大意:依次输入n个数,每当输入奇数个数的时候,求出当前序列的中位数(排好序的中位数). 此题可用各种方法求解. 排序二叉树方 ...
- 传递给系统调用的数据区域太小。 (异常来自 HRESULT:0x8007007A)
在做结构体向字节数组转换的时候,常遇到"传递给系统调用的数据区域太小"的错误,究其原因是因为英文与汉字的编码方式不同,一个汉字等于两个字节,而一个英文字母等于1个字节.所以,对于如 ...
- mysql 数据包太小会引发错误信息
Error querying database. Cause: com.mysql.cj.jdbc.exceptions.PacketTooBigException: Packet for quer ...
- HP1020打印机“传递给系统调用的数据区域太小” 如何处理?
如果电脑上曾经安装过 HP LaserJet 激光打印机的驱动程序,重新安装驱动程序之前,需要完全卸载以前安装的驱动程序,否则可能会出现无法找到设备或者安装不上驱动程序的现象. 安装网站下载的即插即用 ...
- POJ 3784.Running Median
2015-07-16 问题简述: 动态求取中位数的问题,输入一串数字,每输入第奇数个数时求取这些数的中位数. 原题链接:http://poj.org/problem?id=3784 解题思路: 求取中 ...
- 【POJ 3784】 Running Median (对顶堆)
Running Median Description For this problem, you will write a program that reads in a sequence of 32 ...
- 【POJ3784】Running Median
Running Median Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3406 Accepted: 1576 De ...
- AcWing:106. 动态中位数(对顶堆)
依次读入一个整数序列,每当已经读入的整数个数为奇数时,输出已读入的整数构成的序列的中位数. 输入格式 第一行输入一个整数PP,代表后面数据集的个数,接下来若干行输入各个数据集. 每个数据集的第一行首先 ...
随机推荐
- 【内核】几个重要的linux内核文件【转】
转自:http://www.cnblogs.com/lcw/p/3159394.html Preface 当用户编译一个linux内核代码后,会产生几个文件:vmlinz.initrd.img, 以及 ...
- MySQL参数设置
InnoDB配置 从MySQL 5.5版本开始,InnoDB就是默认的存储引擎并且它比任何其它存储引擎的使用要多得多.那也是为什么它需要小心配置的原因. 1 innodb_file_per_table ...
- 使用Python扫描网络MAC地址对应的IP地址
#!/usr/bin/env python # -*- coding: utf-8 -*- from scapy.all import srp,Ether,ARP,conf ipscan='192.1 ...
- OSGiBundle出现 Could not find bundle: org.eclipse.equinox.console的解决方案
按照网上教程创建OSGI HelloWorld实例配置run configuration时出现Could not find bundle: org.eclipse.equinox.console 和C ...
- 洛谷P2194HXY烧情侣
传送门啦 这个题可以说是tarjan强连通分量的裸题,但需要维护每个强连通分量的最小值,所以做法就很明确了. 我们先明确几个数组的意思: 1.首先是tarjan缩点中的几个数组: dfn[i]:i点的 ...
- Hexo命令无法找到 -问题修复
本人PC安装hexo按照官方npm方式下载: npm install -g hexo-cli 但是到了控制台,输入hexo总是无法找到该命令,提示:Command not Found!!!,无论git ...
- 获取随机字符串的方法 GetRandomString
方法1:推荐方便. System.Hash 单元 Memo1.Lines.Add(THash.GetRandomString(50)); 方法二(自己写的): function TStrApi.Sui ...
- Springboot + Vue + shiro 实现前后端分离、权限控制
本文总结自实习中对项目对重构.原先项目采用Springboot+freemarker模版,开发过程中觉得前端逻辑写的实在恶心,后端Controller层还必须返回Freemarker模版的ModelA ...
- 开源框架:SDWebImage
http://blog.csdn.net/uxyheaven/article/details/7909373 SDWebImage是我搞iOS以来少数佩服的框架,膜拜一下作者.真的写的非常棒! 这套开 ...
- Kibana安装及简单使用
Kibana安装 参照官方文档即可,这里只做相关操作记录: wget https://artifacts.elastic.co/downloads/kibana/kibana-5.5.0-linux- ...