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

贴AC代码

Posted by 508618087 at 2011-12-20 00:05:29 on Problem 1089
#include <iostream>
using namespace std;
#define Maxsize 50001
struct two
{
	int a;
	int b;
};
int cmp ( const void *m , const void *n )
{
	int c= (*(struct two*)m).a - (*(struct two*)n).a;//根据结构体中data的值进行排序
    if(c>0) return 1;
    else return -1;

}
int main()
{
	int n,i,s,b;
	cin>>n;
	two arr[Maxsize];
	for(i=0;i<n;i++)
		cin>>arr[i].a>>arr[i].b;
	qsort(arr,n,sizeof(struct two),cmp);
	s=arr[0].a;
	b=arr[0].b;
	for( i=0;i<=n-1;++i)
	{
		if(arr[i].a>=s&&arr[i].b<=b)
			continue;
		else if(arr[i].a>b)
		{
			cout<<s<<' '<<b<<endl;
			s=arr[i].a;b=arr[i].b;
		}
		else if(arr[i].a>=s&&arr[i].a<=b&&arr[i].b>b)
		{
			b=arr[i].b;
		}		
	}
	cout<<s<<' '<<b<<endl;
	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