首页 > 其他 > 详细

Codeforces 976C

时间:2018-05-13 14:43:25      阅读:246      评论:0      收藏:0      [点我收藏+]

题意略。

思路:由于题中只要让我们找出嵌套的段就行了,那么我们只需要排序一下就好了。

排序方式:按左端由小到大排,左端一样的时候,右端小的排在前。

技术分享图片

 

 

如果你担心1会因为2的阻隔而不能嵌套3的话,那么2可以保证嵌套3。

#include<bits/stdc++.h>
#define maxn 300005
using namespace std;

struct edge{
    int l,r,id;
    edge(int a = 0,int b = 0,int c = 0){
        l = a,r = b,id = c;
    }
    bool operator<(const edge& e) const{
        if(l != e.l) return l < e.l;
        return r > e.r;
    }
};

edge store[maxn];
int n;

int main(){
    scanf("%d",&n);
    for(int i = 1;i <= n;++i){
        scanf("%d%d",&store[i].l,&store[i].r);
        store[i].id = i;
    }
    sort(store + 1,store + 1 + n);
    int ans1 = -1,ans2 = -1;
    for(int i = 1;i < n;++i){
        if(store[i].l <= store[i + 1].l && store[i].r >= store[i + 1].r){
            ans1 = store[i + 1].id,ans2 = store[i].id;
            break; 
        }
    }
    printf("%d %d\n",ans1,ans2);
    return 0;
}

 

Codeforces 976C

原文:https://www.cnblogs.com/tiberius/p/9032072.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!