HDU 3282 Running Median 动态中位数,可惜数据范围太小
2015-04-02 13:39
218 查看
Running Median
Time Limit: 1 Sec Memory Limit: 256 MB题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=3282Description
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 -3HINT
[b]题意[/b]给你n个数,每次插入一个数,当插入数的数量为奇数的时候,我们就输出中位数
[b]题解:[/b]
这道题要求动态求中位数,但是数据范围太小了,于是我们直接暴力搞就好了
事先排序,然后每次都扫一遍就行了……
[b]代码:[/b]
//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]); else printf(" %d",ans[i]); } printf("\n"); } }
相关文章推荐
- POJ 3784 Running Median 动态求中位数 堆
- POJ 3784 Running Median 动态求中位数 堆
- POJ3784 Running Median 对顶堆维护动态中位数(思维)
- POJ 3784 Running Median 动态求中位数 堆
- [Google面试]10G的数据如何用2G的空间找到中位数(Median)
- iOS根据坐标数据点所在的坐标区域来动态显示到可视范围
- Excel宏_实现对动态数据求均值和落在特定范围的数据的个数
- HDU - 3282 Running Median (动态中位数+优先队列)
- PAT 1057. Stack (30) 求动态数据的中位数, 堆的插入和删除
- iOS根据坐标数据点所在的坐标区域来动态显示到可视范围
- HDU 5349 动态插入删除查询数据-multiset
- hdu 3473 划分树求范围内小于中位数的和与大于中位数的和
- HDU - 3282 Running Median (动态中位数+优先队列)
- 匈牙利算法模板 hdu 1068 题意不清。。。。(数据范围太过随意。。)
- HDU 4719 浅谈数据结构优化双关键字动态规划
- C和指针之动态内存分配(读取范围在1和标准输入读取的size之前每个数据出现的次数)
- poj3784 Running Median查找中位数
- Hdu 5857 Median(给你一个有序的序列,取出连续的两段l1,l2,r1,r2,求这两段合并之后的中位数)
- 动态地往datagirdview中添加数据,当所添加的数据超过datagridview的显示范围后,滚动条就无法显示,程序出现假死状态,(scrollbars=both)
- hdu 5249 KPI (动态中位数,两个set)