1 solutions
-
1
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int id,n; cin>>id>>n; //获得编号和元素个数 cout<<id<<" "<<n/2+1<<endl; int cnt=0; priority_queue<int,vector<int>,greater<int> > up; //小根堆 priority_queue<int> down; //大根堆 for(int i=1;i<=n;i++) { int x; cin>>x; if(up.size()==0||x>=up.top()) //上面没有元素,或者是当前元素大小上面的最小值 { up.push(x); } else //当前元素小于上面的最小值 { down.push(x); } if(up.size()>down.size()+1) //上面元素太多 { down.push(up.top()); up.pop(); } if(down.size()>up.size()) //下面元素太多 { up.push(down.top()); down.pop(); } if(i%2==1) //需要输出动态中位数 { cout<<up.top()<<" "; cnt++; if(cnt%10==0) //10个一行 { cout<<endl; } } } if(cnt%10) cout<<endl; //最后没有换行就补上换行 } return 0; }
- 1
Information
- ID
- 166
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 29
- Accepted
- 8
- Uploaded By