codeforces 620C air conditioner

Question: A restaurant is given the size of the test sample, the number of guests, and the initial temperature of the restaurant, and then give each guest a comfortable temperature range and the time they arrive at the restaurant.
The air conditioner heats up by 1 degree per minute and cools down by one degree per minute or when it is turned off. The temperature does not increase or decrease.
Q: Can every guest be able to adjust the temperature of the restaurant within their comfortable range within the minute they eat
. This question only asks about the feasibility of the specific operation without us. Then we only need to make a difference between the time of a guest’s arrival and the time of the current guest. Within this time difference, the adjustable temperature range of the air conditioner is (l-cha , R+cha) As long as this interval has an intersection with the temperature comfort interval of the current guest, it means that the temperature can reach feasible and then change the interval. As long as this interval is illegal (l>r), it means that the interval has no intersection mark and exit.

Learn the feasibility of this kind of operation to solve the problem

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
struct node
{
    
    
    int t;
    int l;
    int h;
}cu[107];

int main()
{
    
    
    int q;
    cin>>q;
    while(q--)
    {
    
    
        int n,m;
        cin>>n>>m;
        int temp = m;// 记录下饭店的初始温度
        for(int i = 1;i <= n;i ++)
        {
    
    
            cin>>cu[i].t>>cu[i].l>>cu[i].h;
        }
        int L = temp,R = temp,time = 0;
        int flag = 0;
        cu[0].t = 0;
        for(int i = 1;i <= n;i ++)
        {
    
    
            int cha = cu[i].t - cu[i-1].t;
            L = L - cha;
            R = R + cha;
            L = max(L,cu[i].l);
            R = min(R,cu[i].h);
            if(L > R)
            {
    
    
                flag = 1;
                break;
            }
        }
        if(!flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45672411/article/details/104423367