HDU 2037 (Greedy), hdu2037 greedy
Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 2037
Not AC this summer
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission (s): 31608 Accepted Submission (s): 16733
Problem Description "this summer is not AC ?" "Yes ." "What are you doing ?" "Watching the World Cup, dumb !" "@ # $ % ^ & * % ..."
Indeed, the World Cup and fans have a holiday. It is estimated that many acmers will leave their computers away and rush to TV. As fans, you must watch as many complete competitions as possible. Of course, as a good young man in the new age, you will certainly watch other programs, for example, news broadcast (never forget to care about national events), cat6 + 7, Super Girl, and Wang xiaoya's kaixindictionary, suppose you already know the broadcast schedules of all the TV programs you like to watch. Will you arrange them properly? (The goal is to watch as many complete programs as possible.) Input data contains multiple test instances. The first line of each test instance has only one integer n (n <= 100 ), indicates the total number of programs you like to watch, followed by n rows of data. Each row includes two data Ti_s, Ti_e (1 <= I <= n ), the Start Time and end time of the first program, respectively. to simplify the problem, each time is represented by a positive integer. N = 0 indicates that the input is over and is not processed. Output for each test instance, the number of TV programs that can be fully viewed is Output, and the Output of each test instance occupies one line. Sample Input121 33 40 73 815 1915 2010 158 186 125 104 90 Sample Output5 simple greedy questions, details can be found in the algorithm competition entry classic 142 page. 1 # include <cstdio> 2 # include <iostream> 3 # include <algorithm> 4 using namespace std; 5 6 int a [111], B [111]; 7 int n, end, cnt; 8 9 int main () 10 {11 int I, j; 12 while (scanf ("% d", & n), n) 13 {14 for (I = 0; I <n; I ++) 15 scanf ("% d", & a [I], & B [I]); 16 for (I = 0; I <n; I ++) 17 for (j = I; j <n; j ++) 18 {19 if (B [I]> B [j]) 20 {21 swap (B [I], B [j]); 22 swap (a [I], a [j]); // exchange function 23} 24} 25 cnt = 1; 26 end = B [0]; 27 for (I = 1; I <n; I ++) 28 {29 if (a [I]> = end) 30 {31 cnt ++; 32 end = B [I]; 33} 34} 35 printf ("% d \ n", cnt); 36} 37 return 0; 38}View Code