クリーニングシフト/ OpenJ_Bailian - 2376

ファーマージョンは納屋の周りにいくつかのクリーニング家事を行うために彼のN(1 <= N <= 25,000)牛の一部を割り当てています。彼はいつも物事をクリーンアップに取り組ん1頭の牛を持って望んでいるとTシフトに日を分けています(1 <= T <= 1,000,000)、最初のビーイングシフト1と最後ビーイングシフトT.

それぞれの牛は、クリーニングの仕事のために日中の時間のいくつかの間隔でのみ使用可能です。義務を洗浄するために選択されているすべての牛は彼女の区間の全体のために動作します。

できるだけ少数の牛がクリーニングに関与しているとして、(ⅰ)すべてのシフトは、少なくとも一つのそれに割り当てられた牛、および(ii)を持つようにあなたの仕事は、ヘルプに農夫ジョンがシフトにいくつかの牛を割り当てています。それは各シフトに牛を割り当てることができない場合には、印刷-1。

入力

* Line 1: Two space-separated integers: N and T 

* Lines 2..N+1: Each line contains the start and end times of the interval during which a cow can work. A cow starts work at the start time and finishes after the end time.

出力

* Line 1: The minimum number of cows Farmer John needs to hire or -1 if it is not possible to assign a cow to each shift.

サンプル入力

3 10
1 7
3 6
6 10

サンプル出力

2

ヒント

This problem has huge input data,use scanf() instead of cin to read data to avoid time limit exceed. 
INPUT DETAILS: 
There are 3 cows and 10 shifts. Cow #1 can work shifts 1..7, cow #2 can work shifts 3..6, and cow #3 can work shifts 6..10. 
OUTPUT DETAILS: 
By selecting cows #1 and #3, all shifts are covered. There is no way to cover all the shifts using fewer than 2 cows.

問題の意味

给你N,T,再给你N个区间,求最少选择多少个区间能覆盖[1,T]之间所有的整数位置

N <= 25000, T <= 1000000

問題の解決策

コード

PS

おすすめ

転載: www.cnblogs.com/Little-Turtle--QJY/p/12388858.html