| ||||||||||
| 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 | |||||||||
贴AC代码#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator