题目链接:http://codeforces.com/contest/902/problem/A
题意:给n段区间,给定一个长度为m的区间,问n段区间是否能覆盖长度为m的区间。
水题,先排序(按左边优先非递减排序),然后遍历区间过去看,是否有长度为m的区间。
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m;
struct node{
int l, r;
}a[105];
bool cmp(node &s, node &s1)
{
if(s.l == s1.l)
return s.r < s1.r;
return s.l < s1.l;
}
int main()
{
while(cin >> n >> m)
{
for(int i = 0; i < n; i++)
cin >> a[i].l >> a[i].r;
sort(a, a+n, cmp);
int ma = 0;
for(int i = 0; i < n; i++)
{
if(ma >= a[i].l)
ma = max(ma, a[i].r);
}
if(ma == m)
puts("YES");
else
puts("NO");
}
return 0;
}