【Codeforces】976C Nested Segments【排序】

【Codeforces】976C Nested Segments

【题目大意】

给你n个数对(li,ri),让你找到一个i,j,使li<=ljri>=rj,输出任意答案。

【题解】

按照li排序,然后用一个量MAXN,存之前最大的ri,就可以了。

【代码如下】

#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
int n,M,id;
struct xcw{
    int x,y,id;
    bool operator <(const xcw b)const{return x<b.x||(x==b.x&&y>b.y);}
}a[300005];
int read(){
    int ret=0;char ch=getchar();bool f=1;
    for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');
    for(; isdigit(ch);ch=getchar()) ret=(ret<<3)+(ret<<1)+ch-48;
    return f?ret:-ret;
}
int main(){
//  freopen("C.in","r",stdin);
//  freopen("C.out","w",stdout);
    n=read();
    for(int i=1;i<=n;i++) a[i]=(xcw){read(),read(),i};
    sort(a+1,a+1+n);M=a[1].y;id=1;
    for(int i=2;i<=n;i++){
        if(a[i].y<=M){printf("%d %d\n",a[i].id,a[id].id);return 0;}
        if(M<a[i].y) M=a[i].y,id=i;
    }
    printf("-1 -1\n");
    return 0;
}
posted @ 2018-05-01 13:12  XSamsara  阅读(102)  评论(0编辑  收藏  举报