Air Conditioner

姬烨磊
2023-12-01

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.

Input
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.

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 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.
题意:就是给你空调初始温度,空调有三个选择 (每分钟)升 降 不变;再给顾客的温度和来的时间,看看空调能满足所有人嘛。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;
struct cus
{
	int time;
	int low;
	int high;
}a[200];
bool cmp(cus x, cus y)
{
	return x.time < y.time;
}
int main()
{
	int p; cin >> p;
	while (p--)
	{
		bool flag = 0;
		int n, t; cin >> n >> t;int  min = t, max = t;
		for (int i = 1; i <= n; i++)//输入
			cin >> a[i].time >> a[i].low >> a[i].high;
			sort(a + 1, a + n + 1,cmp);//排序
			a[0].time = 0;
			for (int i = 1; i <= n; i++)
			{
				int dt = a[i].time - a[i - 1].time;
				min = min - dt; max = max + dt;
				if (min > a[i].high || max < a[i].low)//这里是自己出错1的地方,这里就是判断顾客的温度在不在空调的温度区间内,直接找反面不就行了
				//如果空调的最低比顾客的最高还大或者最高比顾客最小还小 这两种情况都不满足的不就行了么。
				{
					flag = 1;
					break;
				}//下面是自己第2容易出错的地方,如果空调满足了顾客,那么空调的这次温度应该变成什么?。这个是需要判断的,你不能直接把顾客的温度直接给它
				//得去判断啊  如果 空调最低温度比顾客的大,那么就不变额,如果空调的最低温度比顾客的小,说明这次温度不可能是这个比顾客低的温度。
				min = a[i].low>min?a[i].low:min;
				max = a[i].high<max?a[i].high:max;
			}
			if (flag)
			{
				cout << "NO" << endl;
			}
			else
				cout << "YES" << endl;
	}
}
 类似资料:

相关阅读

相关文章

相关问答