CF1304C.Air Conditioner
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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: ti — the time (in minutes) when the i-th customer visits the restaurant, li — the lower bound of their preferred temperature range, and hi — 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 i-th customer is satisfied if and only if the temperature is between li and hi (inclusive) in the ti-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.
吉东拥有一家烤肉店。店里顾客众多,因此许多人喜欢在到店前进行预约。
吉东竭尽全力满足顾客需求,甚至记住了所有顾客偏好的温度范围!他查看预约清单,希望通过调控餐厅的温度来满足所有顾客。
餐厅配备一台空调,具有三种工作状态:关闭、制热和制冷。当空调关闭时,餐厅温度保持不变;当空调制热时,温度每分钟上升 1 度;当空调制冷时,温度每分钟下降 1 度。吉东可以在任意整数分钟时刻(包括第 0 分钟)将空调切换至任意状态,切换次数不限。空调初始状态为关闭。
每位顾客由三个参数刻画:ti —— 第 i 位顾客到店时间(单位:分钟),li —— 其偏好的温度下限,hi —— 其偏好的温度上限。
若顾客到店瞬间餐厅温度处于其偏好温度范围内,则该顾客被满足。形式化地,第 i 位顾客被满足当且仅当第 ti 分钟时的温度在区间 [li,hi] 内(含端点)。
给定初始温度、预约顾客的到店时间及其偏好温度范围,请你帮助吉东判断是否有可能满足所有顾客。
输入格式
Each test contains one or more test cases. The first line contains the number of test cases q (1≤q≤500). Description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n≤100, −109≤m≤109), where n is the number of reserved customers and m is the initial temperature of the restaurant.
Next, n lines follow. The i-th line of them contains three integers ti, li, and hi (1≤ti≤109, −109≤li≤hi≤109), where ti is the time when the i-th customer visits, li is the lower bound of their preferred temperature range, and hi 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 0.
每个测试包含一个或多个测试用例。第一行包含测试用例的数量 q(1≤q≤500)。随后是测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n≤100,−109≤m≤109),其中 n 表示预约顾客的数量,m 表示餐厅的初始温度。
接下来是 n 行。第 i 行包含三个整数 ti、li 和 hi(1≤ti≤109,−109≤li≤hi≤109),其中 ti 表示第 i 位顾客到访的时间,li 表示其偏好的温度区间的下界,hi 表示其偏好的温度区间的上界。偏好温度区间为闭区间(即包含端点)。
顾客按其到访时间的非递减顺序给出,且当前时间为 0。
输出格式
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).
对于每个测试用例,如果能够满足所有顾客,则输出 “YES”;否则输出 “NO”。
你可以以任意大小写(大写或小写)输出每个字母。
输入输出样例
输入#1
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
输出#1
YES NO YES NO
说明/提示
In the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
- At 0-th minute, change the state to heating (the temperature is 0).
- At 2-nd minute, change the state to off (the temperature is 2).
- At 5-th minute, change the state to heating (the temperature is 2, the 1-st customer is satisfied).
- At 6-th minute, change the state to off (the temperature is 3).
- At 7-th minute, change the state to cooling (the temperature is 3, the 2-nd customer is satisfied).
- At 10-th minute, the temperature will be 0, which satisfies the last customer.
In the third case, Gildong can change the state to heating at 0-th minute and leave it be. Then all customers will be satisfied. Note that the 1-st customer's visit time equals the 2-nd customer's visit time.
In the second and the fourth case, Gildong has to make at least one customer unsatisfied.
在第一种情况下,吉隆东可以通过以下方式调控空调来满足所有顾客的需求:
- 在第 0 分钟,将空调状态切换为制热(此时温度为 0);
- 在第 2 分钟,将空调状态切换为关闭(此时温度为 2);
- 在第 5 分钟,将空调状态切换为制热(此时温度为 2,满足第 1 位顾客);
- 在第 6 分钟,将空调状态切换为关闭(此时温度为 3);
- 在第 7 分钟,将空调状态切换为制冷(此时温度为 3,满足第 2 位顾客);
- 在第 10 分钟,温度将降为 0,从而满足最后一位顾客。
在第三种情况下,吉隆东可在第 0 分钟将空调状态切换为制热并保持不变,即可满足所有顾客。注意:第 1 位顾客与第 2 位顾客的到访时间相同。
在第二种和第四种情况下,吉隆东至少需让一位顾客不满意。
输入解题思路,AI测评打分。不知道怎么写?