简单题
View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 50005
struct Interval
{
int a, b;
}interval[maxn];
int n;
bool operator < (const Interval &a, const Interval &b)
{
if (a.a == b.a)
return a.b < b.b;
return a.a < b.a;
}
int main()
{
//freopen("t.txt", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &interval[i].a, &interval[i].b);
sort(interval, interval + n);
int s = interval[0].a;
int e = interval[0].b;
for (int i = 1; i < n; i++)
{
if (interval[i].a <= e)
e = max(interval[i].b, e);
else
{
printf("%d %d\n", s, e);
s = interval[i].a;
e = interval[i].b;
}
}
printf("%d %d\n", s, e);
return 0;
}