当前位置: 首页 > news >正文

Codeforces 1304C - Air Conditioner(1500)

Air Conditioner

题面翻译

  • 一个餐馆中有个空调,每分钟可以选择上调 1 1 1 个单位的温度或下调 1 1 1 个单位的温度,当然你也可以选择不变,初始的温度为 m m m

  • n n n 个食客,每个食客会在 t i t_i ti 时间点到达,他所能适应的最低温度是 l i l_i li ,最高温度是 h i h_i hi ,他只会在 t i t_i ti 时刻逗留。

  • 如果温度不在食客的适应范围内,他就会不舒服,请你判断,空调能否使得 n n n 位来就餐的食客都感到舒服。

  • 本题多组数据,数据组数不大于 500 500 500

  • 1 ≤ n ≤ 100 1\le n\le 100 1n100 − 1 0 9 ≤ m , l i , h i ≤ 1 0 9 -10^9\le m,l_i,h_i\le 10^9 109m,li,hi109 1 ≤ t i ≤ 1 0 9 1\le t_i\le 10^9 1ti109

  • translate by @ShineEternal。

题目描述

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: $ t_i $ — the time (in minutes) when the $ i $ -th customer visits the restaurant, $ l_i $ — the lower bound of their preferred temperature range, and $ h_i $ — 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 $ l_i $ and $ h_i $ (inclusive) in the $ t_i $ -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.

输入格式

Each test contains one or more test cases. The first line contains the number of test cases $ q $ ( $ 1 \le q \le 500 $ ). Description of the test cases follows.

The first line of each test case contains two integers $ n $ and $ m $ ( $ 1 \le n \le 100 $ , $ -10^9 \le m \le 10^9 $ ), 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 $ t_i $ , $ l_i $ , and $ h_i $ ( $ 1 \le t_i \le 10^9 $ , $ -10^9 \le l_i \le h_i \le 10^9 $ ), where $ t_i $ is the time when the $ i $ -th customer visits, $ l_i $ is the lower bound of their preferred temperature range, and $ h_i $ 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 $ .

输出格式

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

样例 #1

样例输入 #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.

思路:根据题意我们可以知道初始的温度及时间是确定的,且时间是不递减的,我们可以维护一个温度区间与所给的每一个顾客的时间区间取交集如果有一个为空的即为NO,维护交集写法如下

这里是引用

AC代码:

#include<bits/stdc++.h>using namespace std;typedef long long ll;
typedef pair<int, int>PII;
typedef pair<int, double>PDD;
const int N=2e5 +10;
const int MOD = 1e9 + 7;
const int INF=0X3F3F3F3F;
const int dx[]={-1,0,1,0,-1,-1,+1,+1};
const int dy[]={0,1,0,-1,-1,+1,-1,+1}; //马
const int dxx[]={-1,2,1,1,-1,2,-2,-2};
const int dyy[]={2,1,-2,2,-2,-1,-1,1};    
const int M = 1e7 + 10;ll n;
ll t[N], l[N], r[N];int main()
{int T;cin >> T;while(T --){int n, m;cin >> n >> m;for(int i = 1; i <= n; i ++){cin >> t[i] >> l[i] >> r[i];}ll cha = 0, f = 0;//维护一个温度区间 ll l1 = m, r1 = m;//一开始均属于初始温度//当前时间为0for(int i = 1; i <= n; i ++){cha = t[i] - t[i - 1];//两者的时间差l1 -= cha , r1 += cha;//取交集依次取依次变l1 = max(l1, l[i]), r1 = min(r1, r[i]);if(l1 > r1){f = 1;break;}}if(f) puts("NO");else puts("YES");}return 0;
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • MYSQL 优化
  • 高级前端工程师React面试题
  • pikachu靶场通关攻略(XSS)(1~10关)
  • 大模型企业应用落地系列四》基于大模型的对话式推荐系统》大模型底座层
  • 探索Python性能监控的瑞士军刀:psutil的神秘面纱
  • 首发!《物流运输行业电子签最佳实践案例集》重磅发布
  • KRTS网络模块:TCP服务端、客户端实例
  • 基于SpringBoot+Vue+MySQL的小区物业管理系统
  • 什么是BI?BI系统的功能有哪些?哪些人需要BI工具支持?
  • JAVA中的线程池说明一
  • C++ | Leetcode C++题解之第377题组合总和IV
  • 上书房信息咨询:生活投诉满意度调研
  • PyTorch深度学习模型训练流程:(一、分类)
  • Debezium系列之:记录一次命令行可以访问mysql数据库,但是debezium connector无法访问数据库原因排查
  • 掌控安全CTF-2024年8月擂台赛-ez_misc
  • 【402天】跃迁之路——程序员高效学习方法论探索系列(实验阶段159-2018.03.14)...
  • Akka系列(七):Actor持久化之Akka persistence
  • electron原来这么简单----打包你的react、VUE桌面应用程序
  • Java新版本的开发已正式进入轨道,版本号18.3
  • js学习笔记
  • Linux各目录及每个目录的详细介绍
  • Mac转Windows的拯救指南
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • Promise初体验
  • Python 反序列化安全问题(二)
  • React Transition Group -- Transition 组件
  • Redis中的lru算法实现
  • SQL 难点解决:记录的引用
  • 闭包--闭包作用之保存(一)
  • 道格拉斯-普克 抽稀算法 附javascript实现
  • 基于Dubbo+ZooKeeper的分布式服务的实现
  • 简单易用的leetcode开发测试工具(npm)
  • 利用DataURL技术在网页上显示图片
  • 每天10道Java面试题,跟我走,offer有!
  • 区块链技术特点之去中心化特性
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • ​ssh免密码登录设置及问题总结
  • ​软考-高级-信息系统项目管理师教程 第四版【第14章-项目沟通管理-思维导图】​
  • #git 撤消对文件的更改
  • (Java入门)抽象类,接口,内部类
  • (Matlab)使用竞争神经网络实现数据聚类
  • (独孤九剑)--文件系统
  • (二)Eureka服务搭建,服务注册,服务发现
  • (附源码)php新闻发布平台 毕业设计 141646
  • (附源码)spring boot基于Java的电影院售票与管理系统毕业设计 011449
  • (附源码)springboot猪场管理系统 毕业设计 160901
  • (算法)N皇后问题
  • (转)程序员疫苗:代码注入
  • (轉貼) 蒼井そら挑戰筋肉擂台 (Misc)
  • .net core 使用js,.net core 使用javascript,在.net core项目中怎么使用javascript
  • .net core使用ef 6
  • .net 调用php,php 调用.net com组件 --
  • .NET/ASP.NETMVC 深入剖析 Model元数据、HtmlHelper、自定义模板、模板的装饰者模式(二)...
  • .NET开源的一个小而快并且功能强大的 Windows 动态桌面软件 - DreamScene2
  • .net实现头像缩放截取功能 -----转载自accp教程网