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

Sample Input

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

Hint

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.

题目意思:小猪要去拜访朋友,他的房子在x轴0点,朋友的房子位于m点。小猪要使用传送点去拜访朋友,能到朋友家就输出YES,否则输出NO,输入n,然后输入n行传送点和最远能传送的地点[ai,bi],ai是传送地点,bi是传送到的极限。

解题思路;一看到这道题我一开始想到的是会场安排问题,贪心的策略,但是这道题不是这样的,我一开始是想判断彼此相邻的两端是否有空隙,有空隙的话就不能到达,但是这是不对的,前面的极限有可能会很大覆盖掉后面的传送点!!!其实想到这里了,再想一步就可以解决了,我们只需要不断更新x(最远传送距离),每一次传送,如果传送极限大于x就更新,如果x>=n就能够到达。

 #include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int n,m,flag,i,j,r,l;
flag=;
scanf("%d%d",&m,&n);
for(i=; i<m; i++)
{
scanf("%d%d",&l,&r);
if(flag>=l)
{
flag=max(flag,r);
}
}
if(flag>=n)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
return ;
}

Visiting a Friend(思维)的更多相关文章

  1. 2017ICPC北京赛区网络赛 Visiting Peking University(简单思维)

    描述 Ming is going to travel for n days and the date of these days can be represented by n integers: 0 ...

  2. [C#][算法] 用菜鸟的思维学习算法 -- 马桶排序、冒泡排序和快速排序

    用菜鸟的思维学习算法 -- 马桶排序.冒泡排序和快速排序 [博主]反骨仔 [来源]http://www.cnblogs.com/liqingwen/p/4994261.html  目录 马桶排序(令人 ...

  3. Photoshop、Illustrator思维导图笔记

    半年前学习Photoshop时记得的思维导图笔记,可能不是很全,常用的基本都记下了.

  4. CYQ.Data 从入门到放弃ORM系列:开篇:自动化框架编程思维

    前言: 随着CYQ.Data 开始回归免费使用之后,发现用户的情绪越来越激动,为了保持这持续的激动性,让我有了开源的念头. 同时,由于框架经过这5-6年来的不断演进,以前发的早期教程已经太落后了,包括 ...

  5. 计算机程序的思维逻辑 (8) - char的真正含义

    看似简单的char 通过前两节,我们应该对字符和文本的编码和乱码有了一个清晰的认识,但前两节都是与编程语言无关的,我们还是不知道怎么在程序中处理字符和文本. 本节讨论在Java中进行字符处理的基础 - ...

  6. 计算机程序的思维逻辑 (29) - 剖析String

    上节介绍了单个字符的封装类Character,本节介绍字符串类.字符串操作大概是计算机程序中最常见的操作了,Java中表示字符串的类是String,本节就来详细介绍String. 字符串的基本使用是比 ...

  7. 计算机程序的思维逻辑 (31) - 剖析Arrays

    数组是存储多个同类型元素的基本数据结构,数组中的元素在内存连续存放,可以通过数组下标直接定位任意元素,相比我们在后续章节介绍的其他容器,效率非常高. 数组操作是计算机程序中的常见基本操作,Java中有 ...

  8. 计算机程序的思维逻辑 (33) - Joda-Time

    Joda-Time上节介绍了JDK API中的日期和时间类,我们提到了JDK API的一些不足,并提到,实践中有一个广泛使用的日期和时间类库,Joda-Time,本节我们就来介绍Joda-Time.俗 ...

  9. 计算机程序的思维逻辑 (53) - 剖析Collections - 算法

    之前几节介绍了各种具体容器类和抽象容器类,上节我们提到,Java中有一个类Collections,提供了很多针对容器接口的通用功能,这些功能都是以静态方法的方式提供的. 都有哪些功能呢?大概可以分为两 ...

随机推荐

  1. 用Vue的父子组件通信实现todolist的功能

    先上代码 <body> <div id="root"> <div> <input v-model="inputValue&quo ...

  2. Windows 安装 MySQL 8.0.11

    下载并解压 从官方网站下载最新安装包 解压到目标安装目录 新建配置文件 在安装目录新建my.ini文件 添加如下内容(需修改为自己的配置) #----------------------------- ...

  3. Django DTL 加减乘除求余

    django模板只提供了加法的filter,没有提供专门的乘法和除法运算: django提供了widthratio的tag用来计算比率,可以变相用于乘法和除法的计算. 加法 {{value|add:1 ...

  4. java 数组基础学习(一维二维数组)

    1.一维数组 1>静态初始化:数据类型[ ] 变量名 = {元素} 例:int[ ] arr = {1,2} 动态初始化:数据类型[ ] 变量名 = new数据类型[数据长度] 例:int[ ] ...

  5. 使用抓包工具pproxy

    下载地址:https://github.com/hidu/pproxy 一.下载后解压 二.打开pproxy.exe 三.手机连接wifi,设置wifi,代理改为手动,输入代理主机ip,代理主机端口. ...

  6. 大数据学习之Hadoop快速入门

    1.Hadoop生态概况 Hadoop是一个由Apache基金会所开发的分布式系统集成架构,用户可以在不了解分布式底层细节情况下,开发分布式程序,充分利用集群的威力来进行高速运算与存储,具有可靠.高效 ...

  7. 字符编码——python学习

    python学习—字符编码 例如汉字“中” 十进制:20013 二进制:01001110 00101101(unicode)/11100100 10111000 10101101(utf-8) 十六进 ...

  8. DDoS 攻击与防御:从原理到实践

    本文来自 网易云社区 . 可怕的 DDoS 出于打击报复.敲诈勒索.政治需要等各种原因,加上攻击成本越来越低.效果特别明显等趋势,DDoS 攻击已经演变成全球性的网络安全威胁. 危害 根据卡巴斯基 2 ...

  9. A1033

    找出最小开销. 思路: 出发点的加油站编号设为0,终点的加油站编号设为n,其他加油站编号按距离依次排序. 如果0号加油站的距离!=0,则无法出发,行驶距离为0. 从起点开始,寻找规则为,如果存在油价小 ...

  10. 编译Libuv

    Libuv https://github.com/libuv/libuv LibSourcey是基于libuv,集合了第三方用于视频流的开源库,使用C++11. 下载最新 https://dist.l ...