区间
2006-10-31 16:45 老博客哈 阅读(450) 评论(0) 编辑 收藏 举报/*
http://acm.hnu.cn:8080/online/?action=problem&type=show&id=10106
*/
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
bool Comp( pair<int,int> elem1, pair<int,int> elem2 )
{
if(elem1.first == elem2.first)
{
return elem1.second < elem2.second;
}
else
{
return elem1.first < elem2.first;
}
}
int main()
{
pair<int, int> p[50000];
int n;
int i;
cin >> n;
for(i = 0; i < n; i++)
{
cin >> p[i].first >> p[i].second;
}
sort(p, p + n,Comp);
int start = p[0].first;
int end = p[0].second;
for(i = 1; i < n;i++)
{
if(p[i].first <= p[i - 1].second)
end = max(p[i].second,p[i - 1].second);
else
{
cout << start << ' ' << end << endl;
start = p[i].first;
end = p[i].second;
}
}
cout << start << ' ' << end << endl;
return 0;
}
http://acm.hnu.cn:8080/online/?action=problem&type=show&id=10106
*/
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
bool Comp( pair<int,int> elem1, pair<int,int> elem2 )
{
if(elem1.first == elem2.first)
{
return elem1.second < elem2.second;
}
else
{
return elem1.first < elem2.first;
}
}
int main()
{
pair<int, int> p[50000];
int n;
int i;
cin >> n;
for(i = 0; i < n; i++)
{
cin >> p[i].first >> p[i].second;
}
sort(p, p + n,Comp);
int start = p[0].first;
int end = p[0].second;
for(i = 1; i < n;i++)
{
if(p[i].first <= p[i - 1].second)
end = max(p[i].second,p[i - 1].second);
else
{
cout << start << ' ' << end << endl;
start = p[i].first;
end = p[i].second;
}
}
cout << start << ' ' << end << endl;
return 0;
}