QUEST5 - Nail Them
To get to the treasure, Jones must complete one more task. He comes across a table, where there are a number of wooden planks lying along the length of the table. He notices that the width of the table is exactly equal to the width of every plank on it. The planks are so heavy that they cannot be manually moved in any way. Some of these wooden planks are overlapping. Jones has a hammer and the Gods grant him infinite nails. The planks have to be joined to the table with nails such that every plank is connected to the table through at least one nail. The nails are of sufficient length, and have to be hammered vertically into the table. One or more planks can be joined to the table through a single nail provided they have a common overlap. Find out the minimum number of nails he needs to nail all planks to the table.
Input
- The first line of the input is a positive integer t <= 20, denoting the number of tables.
- The descriptions of the table follow one after the other.
- Table description:
- The first line of the description of the kth table contains a positive integer n (n <= 10010), the number of planks on it.
- This is followed by n lines containing the description of the planks.
- The description of each plank is a pair of integers a and b (0 <= a <= b <= 10000010), denoting the distance of the left end and right end of the plank from the left end of the table.
Output
The output must contain t lines , the kth line corresponding to the kth table. The output on the kth line must be an integer ik, the minimum number of nails required.
Example
Input:
2
3
1 5
3 5
2 4
2
1 4
4 5
Output:
1
1
hide comments
Simes:
2023-04-30 12:07:14
as Matija MartiniƦ and Rajarshi Sarkar said: In the second example test case, if the right end of the first plank is at a distance 4 from the left end of the table, and the left end of the second plank is at a distance 4 from the left end of the table, then the planks touch, but don't overlap. How can one nail be enough? |
|
prince_agrawal:
2020-10-22 00:13:36
Almost same Algorithm as in Interval Scheduling Problem/Busyman
|
|
Shubham Jadhav:
2017-05-26 13:30:48
Really nice question. AC in one go :) |
|
sudeep_11:
2017-02-04 15:42:21
Just a small modification in solution of BUSYMAN and its done ! |
|
blazekid_dtu:
2016-04-07 14:44:26
solve BUSYMAN before this. |
|
gratitude:
2015-03-08 13:49:39
similar to interval scheduling problem |
|
||N0VICE||:
2014-09-14 15:32:35
Nice and easy :) |
|
Archit Jain:
2014-09-12 15:11:01
too easy
|
|
Matija MartiniƦ:
2014-05-27 19:58:43
same doubt...
|
|
Rajarshi Sarkar:
2013-05-10 12:44:34
1 4
|
Added by: | Kashyap KBR |
Date: | 2005-12-08 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 VB.NET |