zoukankan      html  css  js  c++  java
  • Border

    题目大意:有N对区间现在剔除一些区间,这些区间被另一些区间完全包含,如,Ai<Bi, Bj<Aj, A完全包含B,求出来这样被包含的区间个数。

    分析:首先按照第一个数字先进行一下排序,然后剩下的就是简单的判断更新了....................

    代码如下:

    ======================================================================================================

    #include<stdio.h>
    #include<vector>
    #include<algorithm>
    using namespace std;
    
    const int MAXN = 16007;
    
    struct node
    {
        int x, y;
        friend bool operator <(const node &t1, const node &t2)
        {
            return t1.x < t2.x;
        }
    }date[MAXN];
    
    int main()
    {
        int N;
    
        scanf("%d", &N);
    
        for(int i=0; i<N; i++)
            scanf("%d%d", &date[i].x, &date[i].y);
        sort(date, date+N);
    
        int ans=0, x=-1, t1=0, t2=0;
    
        for(int i=0; i<N; i++)
        {
            if(x != date[i].x)
            {
                if(t1 < t2)
                    t1 = t2;
                t2 = date[i].y;
                x = date[i].x;
            }
    
            if(t1 > date[i].y)
                ans++;
            t2 = max(t2, date[i].y);
        }
    
        printf("%d
    ", ans);
    
        return 0;
    }
  • 相关阅读:
    镜像源收集
    关于vue-cli3脚手架安装后回退到vue-cli2版本的问题
    window.location 对象
    常用正则表达式
    前端开发工程师面试题
    面试题1
    Echarts.js使用
    swipe.js 使用方法
    canvas基础API
    前端面试题集锦
  • 原文地址:https://www.cnblogs.com/liuxin13/p/4855422.html
Copyright © 2011-2022 走看看