# UVa-10020 - Minimal coverage

The Problem

Given several segments of line (int the X axis) with coordinates [Li,Ri]. You are to choose the minimal amount of them, such they would completely cover the segment [0,M].

The Input

The first line is the number of test cases, followed by a blank line.

Each test case in the input should contains an integer M(1<=M<=5000), followed by pairs "Li Ri"(|Li|, |Ri|<=50000, i<=100000), each on a separate line. Each test case of input is terminated by pair "0 0".

Each test case will be separated by a single line.

The Output

For each test case, in the first line of output your programm should print the minimal number of line segments which can cover segment [0,M]. In the following lines, the coordinates of segments, sorted by their left end (Li), should be printed in the same format as in the input. Pair "0 0" should not be printed. If [0,M] can not be covered by given line segments, your programm should print "0"(without quotes).

Print a blank line between the outputs for two consecutive test cases.

Sample Input

2

1
-1 0
-5 -3
2 5
0 0

1
-1 0
0 1
0 0
Sample Output

0

1
0 1
Alex Gevak

September 10, 2000 (Revised 2-10-00, Antonio Sanchez)

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
int m;
cin >> m;
while(m--)
{
int r;
vector<int> number;
cin >> r;
for(int i = 0; i < r; ++i)
{
int temp;
cin >> temp;
number.push_back(temp);
}
sort(number.begin(), number.end());// 排序
int mid_tag = r / 2;
int medians = number[mid_tag], distance = 0, i;
for(i = 0; i <= mid_tag; ++i)
{
distance += number[mid_tag] - number[i];
}
for(;i < r; ++i)
{
distance += number[i] - number[mid_tag];
}
cout << distance << endl;
}
return 0;
}

• 本文已收录于以下专栏：

## Uva-10020 (Minimal coverage)

• qq_37753409
• 2018年01月13日 23:23
• 17

## UVA Minimal coverage （贪心）

Description  Minimal coverage  The Problem Given several se...
• yeguxin
• 2015年02月02日 16:12
• 649

## UVA 10020——Minimal coverage（最小覆盖，贪心问题）

• WSS_ang
• 2017年08月23日 23:52
• 96

## 判定覆盖(Decision coverage)

• u012814506
• 2014年04月24日 18:54
• 758

## UVA 10020 Minimal coverage(贪心 + 区间覆盖问题）

Minimal coverage  The Problem Given several segments of line (int the X axis) with c...
• u011217342
• 2013年08月16日 16:37
• 1276

## Minimal Coverage（ural1303,区间贪心）

http://acm.timus.ru/problem.aspx?space=1&num=1303 http://acm.hust.edu.cn/vjudge/problem/viewProbl...
• JHC23
• 2013年08月18日 09:53
• 557

## 10020 - Minimal coverage（水题）

• weizhuwyzc000
• 2015年09月13日 21:56
• 390

## UVa 10020 Minimal coverage (贪心&区间覆盖)

10020 - Minimal coverage Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_...
• synapse7
• 2013年10月29日 19:28
• 1551

## UVa 10020 & POJ 2620 - Minimal coverage

• u014247806
• 2014年06月05日 18:47
• 829

## [贪心]uva10020 Minimal coverage

• u011194165
• 2014年03月12日 20:58
• 729

举报原因： 您举报文章：UVa-10020 - Minimal coverage 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)