zoukankan      html  css  js  c++  java
  • Codeforces 976C

    题意略。

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

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

    如果你担心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
    ",ans1,ans2);
        return 0;
    }
  • 相关阅读:
    了解JVM原理
    封装JS
    “==”和Equals的区别
    SpringMVC请求RequestMapping() 请求乱码
    博客25周
    博客24周
    博客23周
    博客22周
    博客第21周
    博客第21周
  • 原文地址:https://www.cnblogs.com/tiberius/p/9032072.html
Copyright © 2011-2022 走看看