| ||||||||||
Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
刚学了AVL树,想找一题练习一下。结果搞了半条还是写不好,最后用set水掉算了。。#include<iostream> #include<cstdio> #include<set> using namespace std; struct node { node(int a,int b):num(a),p(b){} int num; int p; bool operator < (const node a)const { return p<a.p; } }; int main() { int com,k,p; set<node> s; while(scanf("%d",&com)&&com) { switch(com) { case 1: { scanf("%d%d",&k,&p); s.insert(node(k,p)); }break; case 2: { if(s.empty()) cout<<0<<endl; else { cout<<(*(--s.end())).num<<endl; s.erase(--s.end()); } }break; case 3: { if(s.empty()) cout<<0<<endl; else { cout<<(*s.begin()).num<<endl; s.erase(s.begin()); } }break; } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator