A11567 | Visiting a Friend
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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 $a_{i}$ and $b_{i}$ ( $0<=a_{i}<=b_{i}<=m$ ), where $a_{i}$ is the location of the $i$ -th teleport, and $b_{i}$ is its limit.
It is guaranteed that $a_{i}>=a_{i-1}$ for every $i$ ( $2<=i<=n$ ).
The next $n$ lines contain information about teleports.
The $i$ -th of these lines contains two integers $a_{i}$ and $b_{i}$ ( $0<=a_{i}<=b_{i}<=m$ ), where $a_{i}$ is the location of the $i$ -th teleport, and $b_{i}$ is its limit.
It is guaranteed that $a_{i}>=a_{i-1}$ for every $i$ ( $2<=i<=n$ ).
输出格式
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).
You can print each letter in arbitrary case (upper or lower).
输入输出样例
输入 #1
3 5 0 2 2 4 3 5
输出 #1
YES
输入 #2
3 7 0 4 2 5 6 7
输出 #2
NO
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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted