zoukankan      html  css  js  c++  java
  • [CF1304C] Air Conditioner

    维护一区间 ([l,r])

    人按照时间升序

    考虑 ((l_i, h_i, t_i)),当前的所有区间与这个区间取交

    推到 (t_{i+1}) 时,所有区间的端点向两边扩张即可

    注意把空掉的区间删掉

    #include <bits/stdc++.h>
    using namespace std;
    
    const int N = 105;
    int q,n,m,t[N],l[N],h[N];
    
    struct interval {
        int l,r;
        void cut(int ql,int qr) {
            l=max(l,ql);
            r=min(qr,r);
        }
        void expand(int t) {
            if(l>r) return;
            l-=t;
            r+=t;
        }
    } I;
    
    signed main() {
        ios::sync_with_stdio(false);
        cin>>q;
        while(q--) {
            cin>>n>>m;
            for(int i=1;i<=n;i++) {
                cin>>t[i]>>l[i]>>h[i];
            }
            for(int i=1;i<=n;i++) {
                for(int j=1;j<i;j++) {
                    if(t[i]<t[j]) {
                        swap(t[i],t[j]);
                        swap(l[i],l[j]);
                        swap(h[i],h[j]);
                    }
                }
            }
            I={m,m};
            for(int i=1;i<=n;i++) {
                I.expand(t[i]-t[i-1]);
                I.cut(l[i],h[i]);
            }
            if(I.l <= I.r) puts("YES");
            else puts("NO");
        }
    }
    
  • 相关阅读:
    Dapper 基础用法
    测试的分类
    Python
    MySQL数据库的增删改查
    Python面向对象之
    Python面向对象之
    Python
    HTML5/CSS3/JS笔记
    Python-Flask框架之
    Python进程与线程
  • 原文地址:https://www.cnblogs.com/mollnn/p/12321947.html
Copyright © 2011-2022 走看看