题目传送门
/*
题意:最少需要多少条线段能覆盖[0, m]的长度
贪心:首先忽略被其他线段完全覆盖的线段,因为选取更长的更优
接着就是从p=0开始,以p点为标志,选取 (node[i].l <= p && p < node[i+1].l)
详细解释:http://www.cnblogs.com/freezhan/p/3219046.html
*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 1e6 + ;
const int INF = 0x3f3f3f3f;
struct Node
{
int l, r;
}node[MAXN], ans[MAXN];
bool cmp(Node x, Node y)
{
if (x.l == y.l) return x.r > y.r;
else return x.l < y.l;
}
int main(void) //URAL 1303 Minimal Coverage
{
//freopen ("R.in", "r", stdin);
int m;
while (scanf ("%d", &m) == )
{
int n = ; int u, v;
while (scanf ("%d%d", &u, &v) == && (u || v))
node[++n].l = u, node[n].r = v;
sort (node+, node++n, cmp);
int k = ;
for (int i=; i<=n; ++i) //cover
{
if (node[k].l < node[i].l && node[k].r < node[i].r)
{
node[++k] = node[i];
}
}
n = k; int p = ; int cnt = ;
node[n+].l = node[n+].r = m + ;
for (int i=; i<=n; ++i)
{
if (node[i].l <= p && p < node[i+].l)
{
ans[++cnt] = node[i]; p = node[i].r;
}
if (p >= m)
{
printf ("%d\n", cnt);
for (int i=; i<=cnt; ++i)
{
printf ("%d %d\n", ans[i].l, ans[i].r);
}
break;
}
}
if (p < m) puts ("No solution");
}
return ;
}
/*
No solution
*/