| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
1A,贴个代码吧。。#include <iostream>
#include <algorithm>
using namespace std;
struct interval{
int a,b;
}I[50000];
int cmp(const void * a,const void * b){
interval *aa,*bb;
aa=(interval*)a;
bb=(interval*)b;
if (aa->a==bb->a)
return bb->b-aa->b;
else if (aa->a<bb->a)
return -1;
return 1;
}
int main()
{
int n;
int i,j;
scanf("%d",&n);
for (i=0;i<n;i++) scanf("%d%d",&I[i].a,&I[i].b);
qsort(I,n,sizeof(interval),cmp);
int a,b;
a=I[0].a,b=I[0].b;
for (i=1;i<n;i++){
if (I[i].a>b){
printf("%d %d\n",a,b);
a=I[i].a;
b=I[i].b;
}
else b=max(I[i].b,b);
}
printf("%d %d\n",a,b);
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator