Codeforces 845 C Two TVs

题目地址
题意:你是土豪,你有两台电视机,你有n个想看的节目,在同一台电视机上不能看a~b时间和b~c时间的,就是说不能看一档节目的结束时间等于另一档节目的开始时间的节目。
思路:按照时间进行排序,维护两台电视机现在播放的节目的结束时间就好了,直接模拟求,详细看代码

#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define N 200010
#define M 90010
#define LL __int64
#define inf 0x3f3f3f3f
#define lson l,mid,ans<<1
#define rson mid+1,r,ans<<1|1
#define getMid (l+r)>>1
#define movel ans<<1
#define mover ans<<1|1
using namespace std;
const LL mod = 1e9 + 7;
struct node {
    int st, en;
}TV[N];
bool cmp(node a, node b) {
    if (a.st == b.st) {
        return a.en < b.en;
    }
    return a.st < b.st;
}
int main() {
    cin.sync_with_stdio(false);
    int n;
    int tv1, tv2;
    bool flag;
    while (cin >> n) {
        tv1 = -1;
        tv2 = -1;
        flag = true;
        for (int i = 0; i < n; i++) {
            cin >> TV[i].st >> TV[i].en;
        }
        sort(TV, TV + n, cmp);
        for (int i = 0; i < n&&flag; i++) {
            if (tv1 < TV[i].st) {
                tv1 = TV[i].en;
            }
            else {
                if (tv2 < TV[i].st) {
                    tv2 = TV[i].en;
                }
                else {
                    flag = false;
                }
            }
        }
        if (flag) {
            cout << "YES" << endl;
        }
        else {
            cout << "NO" << endl;
        }
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值