这道题目很简单,就是一个排序,然后贪心就可以了1A。
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
struct node
{
int a;
int b;
bool operator <(const node & other)const
{
if(a<other.a) return true;
else if(a==other.a)
{
if(b<other.b)return true;
else return false;
}
else
return false;
}
}num[50010];
int main()
{
int n,a,b;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d%d",&num[i].a,&num[i].b);
}
sort(num,num+n);
a=num[0].a;
b=num[0].b;
for(int i=1;i<n;i++)
{
if(b<num[i].a)
{
printf("%d %d/n",a,b);
a=num[i].a;
b=num[i].b;
}
else if(b<num[i].b)
b=num[i].b;
}
printf("%d %d/n",a,b);
return 0;
}