寒假刷題35:Codeforces Round #620 C. Air Conditioner

題目鏈接:

C. Air Conditioner

題目解析:

爲啥這題標籤裏面有DP啊...狀態轉移?

從初始溫度開始,能求出下一位客人進門時可達到的溫度區間。如果和此客人的舒適區間不相交,則輸出NO;反之,取交集作爲新的狀態

AC代碼:

#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int q,n,m,t,l,h;
int main()
{
    cin>>q;
    while(q--)
    {
        cin>>n>>m;
        int L=m,R=m,now=0,ans=1;
        for(int i=1;i<=n;i++)
        {
            cin>>t>>l>>h;
            L=L-(t-now);
            R=R+(t-now);
            now=t;
            if(R<l || L>h) ans=0;
            L=max(L,l);
            R=min(R,h);
        }
        if(ans) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章