Codeforces Round #620 (Div. 2) C. Air Conditioner
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 (1≤q≤5001≤q≤500 ). Description of the test cases follows.
The first line of each test case contains two integers nn and mm (1≤n≤1001≤n≤100 , −109≤m≤109−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 (1≤ti≤1091≤ti≤109 , −109≤li≤hi≤109−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
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
YES
NO
YES
NO
大意就是一个餐馆有一台可以调温的空调,在某一时刻可以选择升温一度,不变或者降温一度,餐馆有一个初始温度m,同时有m个顾客,每个顾客i是满意的当且仅当ti时刻的温度在他的接受范围之内(由输入给出),问这个餐馆能否通过某种调温方式让每个顾客否满意。
可以这么想,先对顾客按进入时间排序,建立两个变量up和down存储当前可调至的最高温和最低温,初始时刻up=down=m。从上一时刻到当前时刻,先更新up为 up + ( ti - t i-1 ),更新down为 down - ( ti - t i-1 ),这说明更新后从上一时刻到这一时刻,餐馆可以将温度调到[down,up]区间的任何一个温度,然后判断当前时刻顾客的舒适温度区与[down,up]是否有交集,没有的话直接break,输出NO,如果能让所有人都满意的话输出YES。
比赛时匆忙写的代码比较丑,参考下意思就行。
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct peo
{
int t;
int l;
int h;
}p[];
bool cmp(peo a,peo b)
{
return a.t<b.t;
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n>>m;
int i,j;
for(i=;i<=n;i++)
{
int x1,x2,x3;
scanf("%d%d%d",&x1,&x2,&x3);
p[i].t=x1;
p[i].l=x2;
p[i].h=x3;
}
sort(p+,p+n+,cmp);
bool flag=;
int up=m;
int down=m;
p[].t=;
for(i=;i<=n;i++)
{
up+=(p[i].t-p[i-].t);
down-=(p[i].t-p[i-].t);
if(p[i].l>up||p[i].h<down)
{
flag=;
break;
}
if(up<=p[i].h&&up>=p[i].l&&down<=p[i].l)
{
up=up;
down=p[i].l;
}
else if(up>=p[i].h&&down<=p[i].h&&down>=p[i].l)
{
up=p[i].h;
down=down;
}
else if(up>p[i].h&&down<p[i].l)
{
up=p[i].h;
down=p[i].l;
}
else if(up<p[i].h&&down>p[i].l)
{ }
cout<<up<<' '<<down<<endl;
}
if(flag==)
{
cout<<"NO"<<endl;
}
else
{
cout<<"YES"<<endl;
}
}
return ;
}
Codeforces Round #620 (Div. 2) C. Air Conditioner的更多相关文章
- Codeforces Round #620 (Div. 2)
Codeforces Round #620 (Div. 2) A. Two Rabbits 题意 两只兔子相向而跳,一只一次跳距离a,另一只一次跳距离b,每次同时跳,问是否可能到同一位置 题解 每次跳 ...
- Codeforces Round #620 (Div. 2) A-F代码 (暂无记录题解)
A. Two Rabbits (手速题) #include<bits/stdc++.h> using namespace std; typedef long long ll; int ma ...
- Codeforces Round #620 (Div. 2) 题解
A. Two Rabbits 思路: 很明显,如果(y-x)%(a+b)==0的话ans=(y-x)/(a+b),否则就为-1 #include<iostream> #include< ...
- Codeforces Round #620 (Div. 2) A. Two Rabbits
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a p ...
- Codeforces Round #620 (Div. 2)E LCA
题:https://codeforces.com/contest/1304/problem/E 题意:给定一颗树,边权为1,m次询问,每次询问给定x,y,a,b,k,问能否在原树上添加x到y的边,a到 ...
- Codeforces Round #620 (Div. 2)D dilworld定理
题:https://codeforces.com/contest/1304/problem/D 题意:给定长度为n-1的只含’>'和‘<’的字符串,让你构造出俩个排列,俩个排列相邻的数字之 ...
- Codeforces Round #620 (Div. 2) D
构造一个排列,要求相邻之间的数满足给定的大小关系,然后构造出两个序列,一个序列是所有可能的序列中LIS最长的,一个所有可能的序列中LIS最短的 最短的构造方法:我们考虑所有单调递增的部分,可以发现要让 ...
- Codeforces Round #620 (Div. 2)E(LCA求树上两点最短距离)
LCA求树上两点最短距离,如果a,b之间距离小于等于k并且奇偶性与k相同显然YES:或者可以从a先走到x再走到y再走到b,并且a,x之间距离加b,y之间距离+1小于等于k并且奇偶性与k相同也输出YES ...
- Codeforces Round #620 (Div. 2)D(LIS,构造)
#define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ io ...
随机推荐
- 后端——框架——日志框架——logback——《官网》阅读笔记——第一章节
第一章节搭建了logback日志框架的环境,演示了Hello World的示例,并详细分析了示例. 搭建日志框架的过程非常简单,只需要在项目的classpath上添加以下三个jar包,logback- ...
- MySQL连接池详解
使用场景数据库连接是一种关键的.有限的.昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是针对 ...
- DataGridView 更改Header样式
'必须先设置 EnableHeadersVisualStyles 属性 才能设置Header颜色dgv.EnableHeadersVisualStyles = Falsedgv.ColumnHeade ...
- 08day 操作命令以及目录结构
yum /var/log目录(日志文件)两个重要目录:message--记录系统或服务程序运行状态信息 secure--记录用户登录信息 tail -f 查看日志方法 head 查问文件头部
- unittest 测试套件使用汇总篇
# coding=utf-8import unittestfrom inspect import isfunction def usage(): """also unit ...
- Django Web接口开发
什么是接口 接口一般来讲分为两种: (1)程序内部的接口:方法与方法.模块与模块之间的交互,程序内部抛出的接口,如登录发帖,发帖就必须要登录,如果不登录不能发帖,发帖和登录这两个模块之间就要有交互,就 ...
- iOS-image图片旋转方向
https://blog.csdn.net/qq_36557133/article/details/85760469 最近在做项目的时候发现资源包内的图片的方向不对,但也不想让UI切一个新图,所以需要 ...
- 201771010135 杨蓉庆《面对对象程序设计(java)》第十七周学习总结
1.实验目的与要求 (1) 掌握线程同步的概念及实现技术: (2) 线程综合编程练习 一.理论知识 ⚫ 线程同步 (1)多线程并发运行不确定性问题解决方案:引入线 程同步机制,使得另一线程要使用该方法 ...
- 什么是DO / DTO / BO / VO /AO ?
转载:https://blog.csdn.net/ouzhuangzhuang/article/details/86644476 POJO 是 DO / DTO / BO / VO 的统称. DO(D ...
- 2000G电脑大型单机游戏合集
激活码 游戏名称(ctrl+F查找) 下载链接005875 艾迪芬奇的记忆 游戏下载链接http://pan.baidu.com/s/1t2PYRAj546_1AcOB-khJZg554158 暗影: ...