有种半贪心的感觉。用两个变量记录所能到达的范围,然后判断m在不在范围内即可。
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#define ll long long
#define maxn 10001
using namespace std;
struct Node{
int x;
int y;
}node[105];
int main(){
int n,m;
bool flag=false;
int x;
int y;
while(cin>>n>>m){
flag=false;
for(int i=0;i<n;i++)
cin>>node[i].x>>node[i].y;
x=node[0].x;
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;
}