Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

刚学了AVL树,想找一题练习一下。结果搞了半条还是写不好,最后用set水掉算了。。

Posted by 139074241 at 2015-02-08 13:12:30 on Problem 3481
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator