Visiting a Friend(思维)

Origin绘制带差异显著性标记的分组均值条形图|科研论文图表教程(附数据格式模板) 传统柱状图虽能呈现组间均值差异,却隐藏个体数据分布;散点图虽能展示原始数据,却难以直观凸显统计显著性。带差异显著性(*)的分组均值条形图——它以“双层叙事”的创新设计,同时呈现群体特征与个体差异。 阅读详情

Visiting a Friend

Pig is visiting a friend.

Pig's house is located at point 0, and his friend's house is located at point m on an axis.

Pig can use teleports to move along the axis.

To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.

Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds.

Determine if Pig can visit the friend using teleports only, or he should use his car.


Input

The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house.

The next n lines contain information about teleports.

The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit.

It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n).

Output

Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).

Examples
Input
3 5
0 2
2 4
3 5
Output
YES
Input
3 7
0 4
2 5
6 7
Output
NO
Note

The first example is shown on the picture below:

Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.

The second example is shown on the picture below:

You can see that there is no path from Pig's house to his friend's house that uses only teleports.

题意

给出n(100),m(100),然后是n个a,b(0<=a<=b<=m),且a非严格单调递增
表示在坐标轴上有n个在ai处的传送门,每个可以传送到[ai,bi]的任意位置,问是否可以仅通过传送门从0到达m.

解法

一开始我写的一次遍历每个段,如果当前段的左边小于等于前一个段的右边就可以,但是却忘记了如果前一个段直接可以到达m

点,而这个段之后的每个段都是相互独立相互不可达的,这种情况也是可以到达的

看了网上别人的博客写的很巧妙值得学习。

注意到如果位置x可达,那么[0,x]全部可达,所以仅需维护一个最远可达的距离,按顺序遍历传送门即可

code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    int n,m;
    scanf("%d%d",&n,&m);
    int most = 0;
    for(int i = 0; i < n; i++){
        int ta,tb;
        scanf("%d%d",&ta,&tb);
        if(ta <= most)
            most = max(most,tb);
    }
    if(most >= m)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Windows 下 OpenClaw(小龙虾) 安装全记录:从零到一的保姆级图文教程(持续更新中) 本文主要介绍了Windows 下 OpenClaw 安装全记录:从零到一的保姆级图文教程,希望能对学习使用OpenClaw 的同学们有所帮助。 文章目录 1. 背景 2. 实战教程 2.1 步骤一 安装Node.js 2.2 步骤二:安装并配置OpenClaw 2.3 步骤三:配置模型 2.4 步骤四:对话 3. 后续使用步骤 阅读详情

相关推荐

卡尔曼滤波原理详解及系统模型建立(simulink)

卡尔曼滤波原理详解及系统模型建立(simulink) 卡尔曼滤波器 卡尔曼滤波器是在上个世界五六十年代的时候提出的,到今天已经有六十年左右的时间,但卡尔曼滤波算法不管在控制、制导、导航或者通讯方面对数据的预测能力依然处在一个不可撼动的位置上,但是很多人对于其算法内部的工作原理究竟是怎么运作的依然不理解,所以在工程上很多人都只是把卡尔曼滤波当成是一种“黑箱”预测算法,并不清楚内部原理。但实际上没有任...

weixin_43942325的博客 7万+

Visiting a Friend(CodeForces 902A )

Description Pig is visiting a friend. Pig's house is located at point 0, and his friend's house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, P...

Baiyi_destroyer的博客 398

从时序迷宫到稳定通信:FSMC配置中的时间参数深度解析与实战避坑指南

本文深入解析STM32 FSMC配置中的时间参数,特别是AddressSetupTime和DataSetupTime的实战配置技巧。通过STM32F407连接SRAM的实际案例,提供从理论计算到CubeMX配置的全流程指南,帮助开发者避免常见时序陷阱,确保稳定通信。

nginx7reverse的博客 81

A. Visiting a Friend(模拟)

A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pig is visiting a friend. Pig's hous

sdau20163940的博客 472

游戏开发中的AI与RAG技术应用实践

检索增强生成(RAG)技术是当前AI领域的重要突破,它通过结合信息检索与文本生成能力,显著提升了大型语言模型在专业领域的实用性。其核心原理是建立动态知识库,在生成响应前先检索相关专业资料作为上下文。这种技术特别适合解决游戏开发中的复杂问题,如虚幻引擎API查询、角色背景生成等技术场景。在实际工程应用中,RAG系统需要精心设计分层检索策略、缓存机制和硬件加速方案。通过将RAG深度集成到游戏引擎工作流中,开发者可以快速解决技术难题,新成员也能更快掌握引擎特性,大幅提升团队协作效率。

weixin_29323977的博客 532

华为EC6108V9E刷机实战:从U盘准备到开机优化的完整避坑指南

本文提供华为悦盒EC6108V9E刷机与优化的完整实战指南。针对搭载RK3228芯片和安卓4.4.4系统的设备,从型号确认、固件选择、U盘准备,到详细刷机步骤、常见故障排除,以及刷机后的深度性能优化,手把手帮助用户规避风险,让旧盒子焕发新生,成为流畅的全能媒体中心。

weixin_29324401的博客 1188

902A Visiting a Friend

A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Pig is visiting a friend. Pig's hous

memory_qianxiao的博客 727

R语言新手也能搞定!WGCNA分析全流程代码详解(附常见报错解决方案)

本文为R语言新手提供了WGCNA分析的完整代码流程与实战指南。从环境配置、数据准备、软阈值选择、网络构建到模块-表型关联分析,逐步详解核心步骤。重点针对安装依赖、内存不足等常见报错提供了具体解决方案,帮助初学者避开陷阱,顺利完成加权基因共表达网络分析。

terraform7cloud的博客 539

H - Visiting a Friend

Pig is visiting a friend. Pig’s house is located at point 0, and his friend’s house is located at point m on an axis. Pig can use teleports to move along the axis. To use a teleport, Pig should come t...

qq_44134712的博客 268

RT-Thread与ROS2通信:micro-ROS在STM32上的移植实践

本文详细介绍了在STM32平台上使用RT-Thread实时操作系统移植micro-ROS实现与ROS2通信的实践方案。通过对比rosserial方案,重点阐述了micro-ROS基于XRCE-DDS协议栈在数据可靠性(丢包率低于1%)、双模式通信(UDP/串口)以及C/C++混合编程方面的优势,为嵌入式设备与ROS2的高效通信提供了完整解决方案。

emacs5lisp的博客 326

修复Oracle MySQL Server 安全漏洞(CVE-2023-0464)

修复Oracle MySQL Server 安全漏洞(CVE-2023-0464)

路~可以走过 3682

Visiting a Friend

题目大意:佩奇要去朋友家玩,但是他毕竟比较懒,还想乘交通工具,众所周知,只要是交通工具就刁钻的很。 如题,给出的两点是这交通工具所经过的线路,想要到达某地,那么起点和目的地之间的线路不能断开。 我们从图上可以更好的理解。 现在,我们需要做的,就是找到不间断的最大线路长度,注意这里不能用点来标注线路。 例如: 0,1 ; 2,3;的话是0—1,2—3,中间是断开的,用点的话是不断的。(话粗理...

Bearing in mind forever! 313

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

Visiting a Friend(思维)

Description Pig is visiting a friend. Pig's house is located at point0, and his friend's house is located at pointmon an axis. Pig can use teleports to move along the axis. To use a te...

weixin_30632089的博客 185

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

visiting a friend意念传送点

Pig is visiting a friend. 皮格将拜访一位朋友. Pig’s house is located at point 0, and his friend’s house is located at point m on an axis. 皮格的房子在点0处,他朋友在数轴上的点m处. Pig can use teleports to move along the axis...

qq_42397914的博客 435

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

CF-902A-Visiting a friend

题源:https://cn.vjudge.net/problem/1268616/origin Description Pig is visiting a friend. Pig’s house is located at point 0, and his friend’s house is located at point m on an axis. Pig can use teleports ...

枚举星星 304

H - Visiting a Friend CodeForces - 902A

H - Visiting a Friend CodeForces - 902A Pig is visiting a friend. Pig’s house is located at point 0, and his friend’s house is located at point m on an axis. Pig can use teleports to move along the ax...

weixin_43892738的博客 258

A. Visiting a Friend

time limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputPig is visiting a friend.Pig's house is located at point 0, and his friend's house is located at po...

无知的我 780

902A-Visiting a Friend

纪念我第一次CodeForces 的第一次掉分之旅。 本来以为是走向红名的第一步,but,凉凉送给午夜做题的我。 只会一个签到题。only one。。。A. Visiting a Friend time limit per test 1 second memory limit per test 256 megabytes input standard input output s

Cai_Haiq的博客 857

Codeforces 902 A.Visiting a Friend 贪心

题意给出n(100),m(100),然后是n个a,b(0<=a<=b<=m),且a非严格单调递增 表示在坐标轴上有n个在ai处的传送门,每个可以传送到[ai,bi]的任意位置,问是否可以仅通过传送门从0到达m.解法题面很绕,但是注意到如果位置x可达,那么[0,x]全部可达,所以仅需维护一个最远可达的距离,按顺序遍历传送门即可.代码/* LittleFall : Hello! */ #include

秋叶红于二月花 662

Codeforces 902A Visiting a Friend

Visiting a Friend time limit per test:1 secondmemory limit per test:256 megabytesinput:standard inputoutput:standard output Problem Description Pig is visiting a friend. ...

weixin_34416649的博客 114

CF453-A Visiting a Friend (dfs)

题意:给你一个数轴,从0开始出发,只能通过传送站转移,然后问能否通过给定的传送站转移到终点传送站给出坐标,以及其能够移动的范围思路:我们可以想到dfs来搜索路径。由于每个传送站可以进行转移,即记录站点位置(转移时只能这样),然后再用vis记录是否访问(避免重复),到达终点标记为成功记录上由于范围较小所以直接用下标表示位置刚开始WA了一发,然后就怀疑输入有坑,估计是某个点的范围被一直改变。...

122

Visiting a Friend CodeForces - 902A

Pig is visiting a friend.Pig's house is located at point 0, and his friend's house is located at point m on an axis.Pig can use teleports to move along the axis.To use a teleport, Pig should come to a...

七九河开的博客 257

Codeforces Round #453 (Div. 2) A - Visiting a Friend 暴力

暴力涂色 考虑边界 #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0) #define in freopen("in.txt", "r", stdin) #define out f

床前明月光 357

【Codeforces Round #453 (Div. 2) A】 Visiting a Friend

【链接】 我是链接,点我呀:) 【题意】 在这里输入题意 【题解】 维护最右端的端点就好。 【代码】 #include <bits/stdc++.h> using namespace std; int n,m,now = 0; int main(){ #ifdef LOCAL_DEFINE freopen("rush_in.tx...

AWCXV 100

Codeforces Round #453 (Div. 2) A,B

比赛链接:http://codeforces.com/contest/902 比赛时间:12/19 rating:1500->1478 A. Visiting a Friend 【题意】有n个起点和终点已知的传送带,Pig可以从起点移动到传送带上任意一点,已知Pig和他朋友的位置,问pig能否去看望他的朋友。 【题解】遍历每个[左端点,右端点-1],访问过的标记一下,再f

Crystal_02101的博客 309

【第二天】C++类和对象进阶指南:从堆区空间操作到友元的深度掌握

new与C语言中mallocdelete和C语言中free作用基本相同区别:new 不用强制类型转换new在申请空间的时候可以 初始化空间内容。

m0_75045191的博客 511
上一篇: DNA Alignment CodeForces - 520C (思维+快速幂)
下一篇: Hungry Student Problem (水题)
Guuuuuu老师儿
博客等级 码龄9年 259粉丝 718原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值