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

题解:第一发wa,忘考虑是否跑到m了,水题。

代码如下:

#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <ctime>
#define maxn 10007
#define N 107
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define eps 0.000000001
#define mod 1000000007
using namespace std;
typedef long long ll;

struct Node
{
    int x;
    int y;
} node[105];

int main()
{
    int n,m;
    bool flag=false;
    while(cin>>n>>m)
    {
        flag=false;
        for(int i=0; i<n; i++)
            cin>>node[i].x>>node[i].y;
        int x=node[0].x;
        int y=node[0].y;
        if(x>0)
        {
            cout<<"NO"<<endl;
            continue;
        }
        for(int i=1; i<n; i++)
        {
            if(m>=x&&m<=y)
            {
                flag=true;
                break;
            }
            else if(node[i].x<=y&&node[i].y>=y)
            {
                y=node[i].y;
            }
            else if(node[i].x<=y&&node[i].y<=y)
            {
                continue;
            }

        }
        if(m>=x&&m<=y)
            flag=true;
        if(flag)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值