Hdoj 3697 Selecting Courses "greedy"

Source: Internet
Author: User

Selecting CoursesTime limit:2000/1000 MS (java/others) Memory limit:62768/32768 K (java/others)
Total submission (s): 2082 Accepted Submission (s): 543


Problem Description A New semester is coming and students be troubling for selecting courses. Students select their course on the Web Course system. There is n courses, the ith course is available during the time interval (AI,BI). That's means, if you want to select the ith course, you must select it after time Ai and before time Bi. Ai and Bi is all in minutes. A student can only try to select a course every 5 minutes, but the he can start trying at any time, and try as many times as H E wants. For example, if-you-start trying to select-courses at 5 minutes seconds and then-you can-make-other-tries at ten minutes 21 Seconds, minutes seconds,20 minutes seconds ... and so on. A student can ' t select more than one course at the same time. It may happen this no course is available when a student are making a try to select a course

You is to find the maximum number of courses a student can select.


Inputthere is no more than test cases.

The first line of all test case contains a integer n. n is the number of courses (0<N<=300)

Then N lines follows. Each line contains integers Ai and Bi (0<=ai<bi<=1000), meaning, the ith course is available during the T IME interval (AI,BI).

The input ends by N = 0.


Outputfor each test case output a line containing an integer indicating the maximum number of courses that a student can s Elect.

Sample Input
21 104 50

Sample Output
2

Test instructions: There are n courses, the following rule is chosen for the class:

1: Each class has a start and end and must be selected within.

2: No further classes are available after 5 minutes after each selection.

First, according to the end of the order from small to large, because it is every five minutes to choose, then we only need to enumerate the first four times, to see if the course in the beginning and end of time, you can.

Code:



Hdoj 3697 Selecting Courses "greedy"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.