标签:
Description
Input
Output
Sample Input
5 5 6 1 4 10 10 6 9 8 10
Sample Output
1 4 5 10
Source
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #ifdef WIN32 13 #define OT "%I64d" 14 #else 15 #define OT "%lld" 16 #endif 17 using namespace std; 18 typedef long long LL; 19 const int MAXN = 50011; 20 int n; 21 22 struct seq{ 23 int l,r; 24 }a[MAXN]; 25 26 inline bool cmp(seq q,seq qq){ if(q.l==qq.l) return q.r<qq.r; return q.l<qq.l; } 27 28 inline int getint() 29 { 30 int w=0,q=0; 31 char c=getchar(); 32 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); 33 if (c==‘-‘) q=1, c=getchar(); 34 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); 35 return q ? -w : w; 36 } 37 38 39 inline void solve(){ 40 n=getint(); 41 for(int i=1;i<=n;i++) { 42 a[i].l=getint(); a[i].r=getint(); 43 } 44 sort(a+1,a+n+1,cmp); 45 int nowl=a[1].l,nowr=a[1].r; 46 for(int i=2;i<=n;i++) { 47 if(a[i].l>nowr) { 48 printf("%d %d\n",nowl,nowr); 49 nowl=a[i].l; nowr=a[i].r; 50 } 51 else if(a[i].r>nowr) nowr=a[i].r; 52 } 53 54 printf("%d %d",nowl,nowr); 55 } 56 57 int main() 58 { 59 solve(); 60 return 0; 61 }
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5605087.html