📄 pku1089.cpp
字号:
#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct
{
int s, e;
}Interval;
const int size = 51000;
Interval nd[size];
int N;
bool cp(Interval a, Interval b)
{
return a.s < b.s;
}
int max(int x, int y)
{
return x > y ? x : y;
}
int main()
{
int i, pos;
while (scanf("%d", &N) != -1 && N)
{
for (i = 0; i < N; i++)
{
scanf("%d %d", &nd[i].s, &nd[i].e);
}
sort(nd, nd + N, cp);
pos = 0;
for (i = 1; i < N; i++)
{
if (nd[pos].e >= nd[i].s)
{
nd[pos].e = max(nd[pos].e, nd[i].e);
}
else
{
printf("%d %d\n", nd[pos].s, nd[pos].e);
pos = i;
}
}
printf("%d %d\n", nd[pos].s, nd[pos].e);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -