• Gildong owns a bulgogi restaurant


    Gildong owns a bulgogi restaurant. The restaurant has a lot of customers, so many of them like to make a reservation before visiting it.

    Gildong tries so hard to satisfy the customers that he even memorized all customers' preferred temperature ranges! Looking through the reservation list, he wants to satisfy all customers by controlling the temperature of the restaurant.

    The restaurant has an air conditioner that has 3 states: off, heating, and cooling. When it's off, the restaurant's temperature remains the same. When it's heating, the temperature increases by 1 in one minute. Lastly, when it's cooling, the temperature decreases by 1 in one minute. Gildong can change the state as many times as he wants, at any integer minutes. The air conditioner is off initially.

    Each customer is characterized by three values: titi — the time (in minutes) when the ii-th customer visits the restaurant, lili — the lower bound of their preferred temperature range, and hihi — the upper bound of their preferred temperature range.

    A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the ii-th customer is satisfied if and only if the temperature is between lili and hihi (inclusive) in the titi-th minute.

    Given the initial temperature, the list of reserved customers' visit times and their preferred temperature ranges, you're going to help him find if it's possible to satisfy all customers.

    Input

    Each test contains one or more test cases. The first line contains the number of test cases qq (1q5001≤q≤500). Description of the test cases follows.

    The first line of each test case contains two integers nn and mm (1n1001≤n≤100, 109m109−109≤m≤109), where nn is the number of reserved customers and mm is the initial temperature of the restaurant.

    Next, nn lines follow. The ii-th line of them contains three integers titi, lili, and hihi (1ti1091≤ti≤109, 109lihi109−109≤li≤hi≤109), where titi is the time when the ii-th customer visits, lili is the lower bound of their preferred temperature range, and hihi is the upper bound of their preferred temperature range. The preferred temperature ranges are inclusive.

    The customers are given in non-decreasing order of their visit time, and the current time is 00.

    Output

    For each test case, print "YES" if it is possible to satisfy all customers. Otherwise, print "NO".

    You can print each letter in any case (upper or lower).

    Example


    Input
    4
    3 0
    5 1 2
    7 3 5
    10 -1 0
    2 12
    5 7 10
    10 16 20
    3 -100
    100 0 0
    100 -50 50
    200 100 100
    1 100
    99 -100 0
    
    Output
    YES
    NO
    YES
    NO
    

    Note

    In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:

    • At 00-th minute, change the state to heating (the temperature is 0).
    • At 22-nd minute, change the state to off (the temperature is 2).
    • At 55-th minute, change the state to heating (the temperature is 2, the 11-st customer is satisfied).
    • At 66-th minute, change the state to off (the temperature is 3).
    • At 77-th minute, change the state to cooling (the temperature is 3, the 22-nd customer is satisfied).
    • At 1010-th minute, the temperature will be 0, which satisfies the last customer.

    In the third case, Gildong can change the state to heating at 00-th minute and leave it be. Then all customers will be satisfied. Note that the 11-st customer's visit time equals the 22-nd customer's visit time.

    In the second and the fourth case, Gildong has to make at least one customer unsatisfied.

    题解:关于控制空调温度来满足顾客,如果在顾客能接受的范围内则满意,问能否使所有顾客满意

    这题可以先求出每个顾客到达时的可以达到的最低温度 l 和最高温度 r ,并判断在这个温度范围内是否有能让顾客满意的温度值,此时可以设置一个标记 flag ,若有,则继续,但若没有,则将 flag 置为0

    注意,最低温度 l 不能低于能让顾客满意的最低温度,而最高温度 r 也不能高于让顾客满意的最高温度,因为要确保当前顾客到达时是他能够满意的温度值;l=max(l,x);r=min(r,y);

    最后看 flag 的值是否为1,若是则输出 YES ,否则输出 NO

    #include<iostream>
    using namespace std;
    int main()
    {
        int t,n,m,;
        cin>>t;
        while(t--)
        {
            int l,r,q=0;
            cin>>n>>m;
            l=r=m;
            int flag=1;
            for(int i=1;i<=n;i++)
            {
                int t,x,y;
                cin>>t>>x>>y;
                l-=(t-q);
                r+=(t-q);
                q=t;
                if(r<x||l>y)
                    flag=0;
                l=max(l,x);
                r=min(r,y);
            }
            if(flag) printf("YES
    ");
            else
                printf("NO
    ");
        }
        return 0;
    }
  • 相关阅读:
    MEF程序设计指南一:在应用程序中宿主MEF
    Silverlight & Blend动画设计系列十三:三角函数(Trigonometry)动画之飘落的雪花(Falling Snow)
    【Silverlight】Bing Maps开发应用与技巧六:使用样式美化图钉(Pushpin)控件的ToolTip外观
    线程的两种类型
    几种VC++数据库开发技术的比较
    Never use AfxEndThread! 一个非常好的例子
    我的 Visual C++ 6.0学习网站
    DB2 基础: 日期和时间的使用
    Boost::Regex 使用方法 (英文)
    vc访问数据库 (并弹出数据源浏览窗口与用户交互)
  • 原文地址:https://www.cnblogs.com/ylrwj/p/12318715.html
Copyright © 2020-2023  润新知