【Codeforces】976C Nested Segments【排序】

【Codeforces】976C Nested Segments

【题目大意】

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

【题解】

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

【代码如下】

#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;
}

转载于:https://www.cnblogs.com/XSamsara/p/9030300.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值