hrbust1176小陈老师、雪人 map&&priority queue
2014-09-23 00:28
435 查看
//利用map的去重性存储,很好;再用优先队列排序 #include <iostream> #include <algorithm> #include <cstdio> #include <queue> #include <map> using namespace std; const int N=100009; map<int,int> m; struct node{ int r,n; friend bool operator <(const node &a,const node &b){//优先队列只用<,>重载了也没用 return a.n<b.n; } }; priority_queue<node> q; int n,tmp; int main(){ while(scanf("%d",&n)!=EOF){ m.clear(); while(n--){ scanf("%d",&tmp); m[tmp]++; } while(!q.empty())q.pop(); node test; for(map<int,int>::iterator i=m.begin();i!=m.end();i++){ test.n=(*i).second; test.r=(*i).first; //cout<<test.n<<' '<<test.r<<endl; q.push(test); } int ans [3],cnt=0; while(true){ if(q.empty())break; node t1,t2,t3; t1=q.top();q.pop(); cout<<t1.n<<' '<<t1.r<<endl; if(q.empty())break; t2=q.top();q.pop(); cout<<t2.n<<' '<<t2.r<<endl; if(q.empty())break; t3=q.top();q.pop(); cout<<t3.n<<' '<<t3.r<<endl; if(t1.r<t2.r)swap(t1,t2); if(t1.r<t3.r)swap(t1,t3); if(t2.r<t3.r)swap(t3,t2); ans[cnt][0]=t1.r;ans[cnt][1]=t2.r;ans[cnt++][2]=t3.r; if(--(t1.n)>0)q.push(t1); if(--(t2.n)>0)q.push(t2); if(--(t3.n)>0)q.push(t3); } cout<<cnt<<endl; for(int i=0;i<cnt;i++) printf("%d %d %d\n",ans[i][0],ans[i][1],ans[i][2]); } return 0; }
相关文章推荐
- hrbust 哈理工oj 1176 小陈老师、雪人(优先队列)
- hrbust 1176 小陈老师、雪人【map+优先队列】
- 哈理工OJ 1176 小陈老师、雪人(排序+优先队列模拟)
- HrbustOJ 1176 小陈老师、雪人 (STL map 和优先队列)
- HLG 1176 小陈老师、雪人【优先队列+map】
- hbrust 1176 小陈老师、雪人【map+优先队列+栈】
- Hrbust 1176 小陈老师、雪人
- 处理拥有相似结构的表 & map 和 maps 的区别和使用方法
- 清明节,老师出题 "如果你死后,墓志铭打算写点啥?
- Autodesk® 设计增值服务概述(Map 3D )
- 观张庆老师&quot;找工作的几个经验&quot;有感
- map, value> or vector, value> >?
- The SQL Site Map Provider You've Been Waiting For
- aaabbbbccc->a3b4c3的MAP版
- Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/collections/map/LRUMap
- 老师布置作业“牛&quot;的问题
- 读王维树老师的笔记&lt;&lt;程序员的12条经营分享&gt;&gt;感
- 程序人生(程序篇- DynaActionForm类&支持Map的ActionForm(Map-backed ActionForm))
- CodeGear RoadMap fro C++Builder :"Barracuda"(Middle of 2008)
- 看"孙鑫老师谈如何学好编程"