2386728_ac_109ms_416k.cc
来自「北大大牛代码 1240道题的原代码 超级权威」· CC 代码 · 共 43 行
CC
43 行
#include <algorithm>
using namespace std;
struct node
{
int x, y;
}pot[50001];
int n;
bool cmp(struct node a, struct node b)
{
if(a.x==b.x)
return a.y<b.y;
else
return a.x<b.x;
}
int main()
{
int l, r;
int i, j;
scanf("%d",&n);
for(i = 0; i < n; i++)
scanf("%d%d",&pot[i].x,&pot[i].y);
sort(pot,pot+n,cmp);
for(i = 0; i < n; i++)
{
l = pot[i].x,r = pot[i].y;
j = i;
while(j<n&&pot[j].x<=r)
{
if(pot[j].y>r)
r = pot[j].y;
j++;
}
printf("%d %d\n",l,r);
i = j-1;
}
return 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?