企业名称:桐城市南口新型建材有限公司
联系人:崔经理
电话:0556-6568069
手机:18156911555
邮箱:303927413@qq.com
地址:桐城市龙腾街道高桥村
网址: www.nkxxjc.com
企业名称:桐城市南口新型建材有限公司
联系人:崔经理
电话:0556-6568069
手机:18156911555
邮箱:303927413@qq.com
地址:桐城市龙腾街道高桥村
网址: www.nkxxjc.com
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 states: off, heating, and cooling. When it’s off, the restaurant’s temperature remains the same. When it’s heating, the temperature increases by
in one minute. Lastly, when it’s cooling, the temperature decreases by
Each customer is characterized by three values: — the time (in minutes) when the i-th customer visits the restaurant, KaTeX parse error: Expected 'EOF', got '}' at position 5: l_[i}̲ — the lower bound of their preferred temperature range, and
A customer is satisfied if the temperature is within the preferred range at the instant they visit the restaurant. Formally, the customer is satisfied if and only if the temperature is between
and
(inclusive) in the
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.
InputEach test contains one or more test cases. The first line contains the number of test cases
. Description of the test cases follows.
The first line of each test case contains two integers and
, where
Next, lines follow. The
line of them contains three integers
, and
, where ti is the time when the
customer visits,
is the lower bound of their preferred temperature range, and
The customers are given in non-decreasing order of their visit time, and the current time is .
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).
Exampleinput4 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
outputYES NO YES NO
NoteIn the first case, Gildong can control the air conditioner to satisfy all customers in the following way:
AtIn the second and the fourth case, Gildong has to make at least one customer unsatisfied.
题意:有n个顾客,0分钟的时候温度是m,每个顾客在第t时候到,他适应的温度为l到r 问是不是能让所有顾客都在适应温度内。 先进行判断,如果同一时间内进入温度区间不相交的话就输出 ,如果相交就缩小区间。 然后通过计算每个人来的时间差,计算出一个温度最大的区间判断是否满足即可。
// 快速幂求逆元int Fermat(int a, int p) //费马求a关于b的逆元{ return qpow(a, p - 2, p);}
///扩展欧几里得ll exgcd(ll a, ll b, ll &x, ll &y){ if (b == 0) { x = 1; y = 0; return a; } ll g = exgcd(b, a % b, x, y); ll t = x; x = y; y = t - a / b * y; return g;}
const int N = 110;
struct node{ ll t, l, r;} a[N];int n, m, cnt;ll L, R, tim, res;int t;bool flag;
int main(){ sd(t); while (t--) { flag = 0; sdd(n, m); rep(i, 1, n) { slddd(a[i].t, a[i].l, a[i].r); } cnt = 1; rep(i, 2, n) { if (a[i].t == a[cnt].t) { if (a[cnt].r < a[i].l || a[i].r < a[cnt].l) { flag = 1; break; } a[cnt].l = max(a[i].l, a[cnt].l); a[cnt].r = min(a[i].r, a[cnt].r); } else a[++cnt] = a[i]; } if (flag == 1) { puts("NO"); continue; } L = m, R = m, res = 0; rep(i, 1, cnt) { tim = a[i].t - res; L = L - tim; R = R + tim; if (R < a[i].l || a[i].r < L) { flag = 1; break; } L = max(L, a[i].l); R = min(R, a[i].r); res = a[i].t; } if (flag == 1) { puts("NO"); continue; } puts("YES"); } return 0;}