1203. Scientific Conferencetime limit:1.0 Second
Memory limit:64 Mbfunctioning of a scientific conference is usually divided into several simultaneous sections. For example, there is a section in parallel computing, a section on visualization, a section on data compression, and So on. Obviously, simultaneous work of several sections are necessary in order-to-reduce the time for scientific program of the CO Nference and to has more time for the banquet, tea-drinking, and informal discussions. However, it's possible that interesting reports be given simultaneously at different sections. A participant have written out the time-table of all the reports which is interesting for him. He asks you to determine the maximal number of reports he'll be able to attend. Inputthe First line contains the number 1≤
N≤100000 of interesting reports. Each of the next
Nlines contains, integers
Tsand
TeSeparated with a space (1≤
Ts<
Te≤30000). These numbers is the times a corresponding report starts and ends. Time is measured in minutes from the beginning of the conference. Outputyou should output the maximal number of reports which the participant can attend. The participant can attend no, reports simultaneously and any, reports he attends must be separated by at least one Minute. For example, if a report ends at, the next report which can is attended must begin at + or later. Sample
input |
Output |
53 41 56 74 51 3 |
3 |
Chinese Translation
Scientific discussion meetings can often be divided into several different parts. For example, some of the discussion calculation, some discussion of data compression and so on.
In order to save time, several different parts are often held simultaneously in order to have more time to hold banquets, tea, and informal discussions. Also, different sections may have wonderful presentations.
Give the schedule of all reports and ask you to find out how many reports you can participate in.
Input
Total number of first behavior reports N, 1 <= n <= 100000. Next there are n rows, each line having two integers t_s and t_e, a space separated (1 <= t_s < t_e <= 30000), the start and end time of the report, in minutes.
Output
You should output the maximum number of reports that you can participate in. It is not possible to participate in concurrent presentations, and there will be at least one minute difference between the two presentations. For example, if the end time of a report is 15, the start time of the next report that can be attended should be at 16 or later.
---------Gorgeous split-line---------
Analysis : This problem is in the talk of greed when doing the exercise, directly with the greedy write.
This is an ordinary activity selection problem, by the end of the ascending order, and then to compare the start time on the line.
Here is the code that sorts the immediate calls to the quick row
1#include <stdio.h>2#include <algorithm>3 4 using namespacestd;5 6 structhui{7 intS, E;8}wuli[100086 ];9 Ten BOOLcmp (Hui A, Hui b) { One returnA.E <B.E; A } - - intMain () the { - intN, t; - -scanf"%d", &n); + inti; - for(i =1; I <= N; i++ ){ +scanf"%d%d", &wuli[i].s, &wuli[i].e); A } at -Sort (Wuli +1, Wuli +1+N, CMP); - - intET = wuli[1].e; - intCounter =1; - for(i =2; I <= N; i++){ in if(wuli[i].s >ET) { -ET =wuli[i].e; tocounter++; + } - } the *printf"%d\n", counter); $}
Greedy [DP] [Ural 1203] Scientific Conference