Uva-10020 (Minimal coverage)
原创
©著作权归作者所有:来自51CTO博客作者qq5813099298a32的原创作品,请联系作者获取转载授权,否则将追究法律责任
题目链接: https://vjudge.net/problem/UVA-10020
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
struct _Node{
int left;
int right;
};
bool cmp(_Node rhs1, _Node rhs2)
{
return rhs1.left < rhs2.left;
}
const int MAXN = 100000 + 1;
_Node arr[MAXN];
int ans[MAXN];
int pad[MAXN];
int main()
{
int t;
cin >> t;
while(t--)
{
int key, l, r, cnt = 0, num = 0, k = 0;
cin >> key;
while(cin >> l >> r)
{
if(l == 0 && r == 0) break;
arr[cnt].left = l;
arr[cnt].right = r;
cnt ++;
}
sort(arr, arr + cnt, cmp);
while (k < key) {
int temp = k;
for (int i = 0; i < cnt; i++)
if (arr[i].left <= k && arr[i].right > temp) {
temp = arr[i].right;
ans[num] = i;
}
if (temp == k) {
num = 0;
break;
}
k = temp;
num++;
}
printf("%d\n", num);
for(int i = 0; i < num; ++i) printf("%d %d\n", arr[ans[i]].left, arr[ans[i]].right);
cout << endl;
}
}