题解:Codeforces Round 964 (Div. 4) C
C. Showering
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output
As a computer science student, Alex faces a hard challenge — showering. He tries to shower daily, but despite his best efforts there are always challenges. He takes
He already has
Given all
In the first test case, Alex can shower for the first
Input
The first line contains a single integer
The first line of each test case contains three integers
Then
Additional constraint on the input:
The sum of
Output
For each test case output "YES" (without quotes) if Alex can take a shower for that given test case, and "NO" (also without quotes) otherwise.
You can output "YES" and "NO" in any case (for example, strings "yEs", "yes", and "Yes" will be recognized as a positive response).
题意
小明每天很忙,但是还要洗澡
小明每天只有
小明每天洗澡需要连续的
小明每天要完成
小明做的第
小明的每个任务时间不会重叠
问:小明有空洗澡吗
Example
Input
4 3 3 10 3 5 6 8 9 10 3 3 10 1 2 3 5 6 7 3 3 10 1 2 3 5 6 8 3 4 10 1 2 6 7 8 9
Output
YES YES NO YES
题解
s和以下时间间隔比较
- 最前面的任务和第0小时之间的空闲时间
- 一天最后的的第m小时和最后一个任务结束之间的空闲时间
- 每个任务之间的空闲时间
只要比任意一个时间间隔小
小明就能洗澡了
代码
#include <bits/stdc++.h> #define int unsigned long long #define INF 0x3f3f3f3f #define all(x) x.begin(),x.end() int t = 1; void solve() { int n,s,m; std::cin >> n >> s >> m; std::vector<std::pair<int,int> > a(n); for(int i = 0 ; i < n; i ++) { std::cin >> a[i].first >> a[i].second; } std::sort(all(a)); for(int i = 0 ; i < n ; i ++) { int kong; if(!i) kong = a[i].first - 0; else kong = a[i].first - a[i-1].second; if(kong >= s) { std::cout << "YES\n"; return; } } if(m - a[n-1].second >= s) std::cout << "YES\n"; else std::cout << "NO\n"; } signed main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); std::cin >> t; while(t--) solve(); return 0; }
posted on 2024-08-07 16:12 Jiejiejiang 阅读(60) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
· AI 智能体引爆开源社区「GitHub 热点速览」