POJ 1089
#include <iostream> #include <algorithm> #define MAXN 50005 using namespace std; struct node { int x; int y; bool boo; }; bool op(node a,node b); node _node[MAXN]; int main() { //freopen("acm.acm","r",stdin); int i; int j; int n; int b; int e; scanf("%d",&n); for(i = 0; i < n; ++ i) { scanf("%d",&_node[i].x); scanf("%d",&_node[i].y); } sort(_node,_node+n,op); for(i = 0; i < n; ++ i) { if(i == 0) { b = _node[i].x; e = _node[i].y; } else { if(_node[i].x <= e && _node[i].y >= e) { e = _node[i].y; } else if(_node[i].x > e) { printf("%d %d\n",b,e); b = _node[i].x; e = _node[i].y; } } } // cout<<b<<" "<<e<<endl; printf("%d %d\n",b,e); } bool op(node a,node b) { if(a.x == b.x) { return a.y > b.y; } return a.x < b.x; }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。
技术网站地址: vmfor.com