zoukankan      html  css  js  c++  java
  • P1803 凌乱的yyy题解

    题目传递门

    总结:
    1、按右端点排序。
    2、记录每一个的完成时间,如果下一个排好序的待进行考试的开始时间在本次完成时间后面,即为可选!

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long LL;
    const int N = 110;
    const int M = 1000010;
    int n, ans, finish;
    struct node {
        int l, r;
    } con[M];
    
    //按右端点排序
    bool cmp(const node &a, const node &b) {
        return a.r <= b.r;
    }
    
    int main() {
        cin >> n;
        //输入
        for (int i = 1; i <= n; i++) cin >> con[i].l >> con[i].r;
        //排序
        sort(con + 1, con + 1 + n, cmp);
    
        for (int i = 1; i <= n; i++)
            if (finish <= con[i].l) //如果finish小于遍历于的线段左端点,那么可用。这句话是核心
                ans++, finish = con[i].r; //迭代的过程
    
        cout << ans << endl;
        return 0;
    }
    
  • 相关阅读:
    2021/6/17学期总结
    2021/6/16申请加分
    2021/6/15
    2021/6/14
    2021/6/11
    2021/6/10
    2021/6/9
    2021/6/8
    2021/6/7
    2021/6/5读书笔记
  • 原文地址:https://www.cnblogs.com/littlehb/p/15034091.html
Copyright © 2011-2022 走看看