Codeforces 1304C - Air Conditioner(1500)

news2024/9/21 0:40:08

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;//一开始均属于初始温度//当前时间为0
		for(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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2083497.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【maven】阿里云仓库配置

阿里云公共仓库的配置看起来有多种类型的仓库: 配置指南 我的maven是idea 自带的:D:\Program Files\JetBrains\IntelliJ IDEA 2022.3.1\plugins\maven\lib\maven3\</

突破编程 C++ 设计模式(组合模式)详尽攻略

在软件开发中&#xff0c;设计模式为程序员提供了解决特定问题的最佳实践。设计模式不仅提高了代码的可复用性和可维护性&#xff0c;还能帮助团队更好地进行协作。在这篇文章中&#xff0c;我们将深入探讨组合模式——一种结构型设计模式。 组合模式允许你将对象组合成树形结…

哪里能免费申请IP SSL证书

一、选择可信赖的证书颁发机构 首先&#xff0c;需要选择一个可信赖的证书颁发机构&#xff08;CA&#xff09;。知名的CA机构如JoySSL、Symantec、GlobalSign等提供IP SSL证书服务。这些机构能够提供符合国际标准的SSL证书&#xff0c;确保数据传输的安全性和服务器的身份验证…

Docker 安装 SqlServer

摘要&#xff1a;我们工作当中经常需要拉取多个数据库实例出来做集群&#xff0c;做测试也好&#xff0c;通过 Docker 拉取 SqlServer 镜像&#xff0c;再通过镜像运行多个容器&#xff0c;几分钟就可以创建多个实例&#xff0c;效率是相当的高。 1. docker 拉取镜像 注意&am…

C++与OpenCV联袂打造:智能视觉识别技术的实践与探索

C与OpenCV联袂打造&#xff1a;智能视觉识别技术的实践与探索 1. 环境设置与准备工作1.1 安装OpenCV和配置开发环境1.1.1 下载OpenCV1.1.2 安装OpenCVWindows系统Linux系统 1.1.3 配置OpenCV库 1.2 C编译器的选择与配置1.2.1 Windows系统1.2.2 Linux系统1.2.3 编译器配置 1.3 选…

浏览器中的开源SQL可视化工具:sqliteviz

sqliteviz&#xff1a; 在浏览器中&#xff0c;即刻开启数据可视化之旅。- 精选真开源&#xff0c;释放新价值。 概览 sqliteviz是一个专为数据可视化而设计的单页离线优先PWA&#xff0c;它利用了现代浏览器技术&#xff0c;让用户无需安装任何软件即可在本地浏览器中进行SQL…

助力外骨骼机器人动力学分析

目录 一、动力学分析 二、拉格朗日方程 三、参考文献 一、动力学分析 动力学是考虑引起运动所需要的力&#xff0c;使执行器作用的力矩或施加在操作臂上的外力使操作臂按照这个动力学方程运动。 目前机器人动力学分析中主要采用牛顿-欧拉动力学方程和拉格朗日动力学方程 […

Leetcode面试经典150题-13.罗马数字转整数

解法都在代码里&#xff0c;不懂就留言或者私信&#xff0c;这个是相对简单点的&#xff0c;感觉会在低职级面试的时候考 class Solution {/**罗马数字转整数还是比较简单的&#xff0c;基本思路&#xff1a;把罗马数字字符串转成字符数组同时创建一个int型数组&#xff0c;遍…

直线公理使初等数学一直将各异直线误为同一线 ——数集相等定义凸显初数一直将各异假R误为R

黄小宁&#xff08;通讯&#xff1a;广州市华南师大南区9-303 510631&#xff09; [摘要]任何图≌自己这一几何最起码常识凸显初等数学一直将无穷多各异直线&#xff08;平面&#xff09;误为同一线&#xff08;面&#xff09;。数集相等的定义凸显&#xff1a;初数应有几何起码…

linux文件——文件系统——文件系统深度理解、学习inode

前言&#xff1a;本篇内容讲解文件系统的细节问题。 在本篇内容中&#xff0c; 我们在学习文件系统的过程中&#xff0c; 我们可以理解inode的原理&#xff0c; 理解如何在文件系统的概念下新建文件&#xff0c; 删除文件&#xff0c; 查找文件&#xff0c; 修改文件等等问题。…

商圣集团:数字创新,引领智慧生活新篇章

在全球化经济不断演进的大潮中&#xff0c;数字经济已成为推动社会进步的关键引擎&#xff0c;重塑着我们的生产与生活模式。商圣集团&#xff0c;以服务社会、创新驱动为核心价值观&#xff0c;致力于利用数字化技术&#xff0c;为个人和企业带来高效、便捷的服务体验&#xf…

【高阶数据结构】秘法(一)——并查集:探索如何高效地管理集合

前言&#xff1a; 前面我们已经学习了简单的数据结构&#xff0c;包括栈与队列、二叉树、红黑树等等&#xff0c;今天我们继续数据结构的学习&#xff0c;但是难度上会逐渐增大&#xff0c;在高阶数据结构中我们要学习的重点是图等 目录 一、并查集的原理 二、并查集的基本操作…

嘉兴银行业绩上涨却市值下滑,新任行长背后的辛酸

撰稿|芋圆 2024年3月6日&#xff0c;秦山核电有限公司&#xff08;以下简称“泰山核电”&#xff09;在上海联合产权交易所转让其所持有的嘉兴银行股份有限公司&#xff08;下称“嘉兴银行”&#xff09;的全部股份630万股的&#xff0c;占嘉兴银行总股本的0.3272%&#xff0c…

【c++】类和对象(上)(类的定义格式、访问限定符、类域、类的实例化、对象的内存大小、this指针)

&#x1f31f;&#x1f31f;作者主页&#xff1a;ephemerals__ &#x1f31f;&#x1f31f;所属专栏&#xff1a;C 目录 前言 一、类的概念及定义 1. 类的定义格式 2. 访问限定符 二、类域 三、类的实例化--对象 1. 实例化的概念 2. 对象的内存大小 四、this指针 …

Vue——认识day02

此处接上一篇文章Vue——初识Vue开始&#xff0c;欢迎大家。 目录 1.MVVM模型 2.Object.defineproperty方法 3.数据代理简介 4.Vue中的数据代理 总结 1.MVVM模型 MVVM模型是一种软件架构模式&#xff0c;用于将用户界面&#xff08;View&#xff09;&#xff0c;业务逻辑&…

牛客周赛 Round 35 (A~G)

本次A~D较为简单&#xff0c;E是一道很好的构造题&#xff0c;FG主要就是考察组合数和约数个数 A.小红的字符串切割 思路 &#xff1a;签到题 void solve() {string s;cin>>s;int lens.size();cout<<s.substr(0,len/2)<<endl<<s.substr(len/2); }B.小…

搭建面向切面编程项目

此项目在整合Mybatis基础上修改&#xff0c;可参考主页的整合Mybatis文章 注解版本 第一步 引入maven坐标 <!-- 切面编程所需jar包--><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId>…

Chapter 04 Vue指令(下)

欢迎大家订阅【Vue2Vue3】入门到实践 专栏&#xff0c;开启你的 Vue 学习之旅&#xff01; 文章目录 前言一、指令修饰符二、v-bind对于样式操作的增强三、v-model应用于表单元素 前言 在 Vue.js 中&#xff0c;指令是带有 v- 前缀的特殊属性&#xff0c;不同属性对应不同的功…

[原理理解] Swin Transformer相对位置编码理解

文章目录 简述相对位置编码的意义直观理解注意力相对位置获取必要性当前位置初步获取利用广播机制获取相对位置索引XY获取最后相对位置1获取最后相对位置2最终的相对位置值嵌入 简述 在看Swin Transformer的时候&#xff0c;一开始在相对位置编码这一块的理解上卡壳了挺久&…

27 Combobox组件

Tkinter ttk.Combobox 组件使用指南 ttk.Combobox 是 Tkinter 的一个高级控件&#xff0c;它结合了文本框和下拉列表的功能&#xff0c;允许用户从预定义的选项列表中选择一个值。ttk 模块是 Tkinter 的一个扩展&#xff0c;提供了更现代的控件外观和行为。以下是对 ttk.Combo…