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

Re:呵呵,终于ac了

Posted by Just_do_it at 2008-04-24 21:10:49 on Problem 1089
In Reply To:呵呵,终于ac了 Posted by:Jack_Jill at 2004-07-07 11:14:10
能看看你的源码吗?谢谢!!!下面的是我写的,不知道错哪了,帮忙看看吧,谢谢!!!
#include <set>
#include <iostream>
using namespace std;

class Pair
{
public:
	int less;
	int bigger;
};

bool operator<(const Pair& p1,const Pair& p2)
{
	if(p1.bigger<p2.bigger)
		return true;
	else if(p1.bigger==p2.bigger)
	{
		if(p1.less<p2.less)
			return true;
		else 
			return false;
	}
	else
		return false;
}

int main(int argc, char* argv[])
{
	set<Pair> pairs;
	Pair p;
	int num;
	cin>>num;
	int i=0;
	while(i<num)
	{
		cin>>p.less>>p.bigger;
		pairs.insert(p);
		i++;
	}

	set<Pair>::iterator it1,it2;
	it1=pairs.begin();
	it2=pairs.begin();
	it2++;

	while(it2!=pairs.end())
	{
		if((*it2).less<=(*it1).less)
		{
			pairs.erase(it1);
			it1=it2;
			it2++;
		}
		else if((*it2).less>(*it1).less&&(*it2).less<=(*it1).bigger)
		{
			(*it2).less=(*it1).less;
			pairs.erase(it1);
			it1=it2;
			it2++;
		}
		else 
		{
			it1++;
			it2++;
		}
	}

	it1=pairs.begin();
	while(it1!=pairs.end())
	{
		cout<<(*it1).less<<' '<<(*it1).bigger<<'\n';
		it1++;
	}
	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