Problem:
This is titled Item greedy algorithm. Our idea is that in the first time each cycle is sorted according to the end (by the end the sooner the crossing, the more programs),
Then start with the first program. Suppose the next program starts at a time that is larger than the start of a program, is the program, in turn, recursion.
Input, which requires two numbers for a set of one number, obvious, then use a two-dimensional array,
In spite of the trouble. But the structure is relatively clear.
Not AC this summer holidayTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 34333 Accepted Submission (s): 18301
Problem Description "Not AC this summer?" ”
Yes
”
"Then what do you do?" ”
"Watch the World Cup." Fool!
”
"@#$%^&*% ..."
That's true. The World Cup is coming. Fans of the festival are also coming, it is expected that a lot of Acmer will also throw away the computer. to the TV.
As a fan, be sure to watch as many full races as possible, of course. As a new era of good youth, you will also see some other programs, such as news broadcast (never forget to care about state affairs), very 6+7, Super girls, and Wang Ya's "Happy Dictionary" and so on, if you already know all the TV programs you like to watch the broadcast schedule. Will you make a reasonable arrangement? (The goal is to be able to see as many full programs as possible)
Input data includes multiple test examples. The first line of each test instance has just an integer n (n<=100), which represents the total number of shows you like to see, followed by n rows of data. Each row consists of two data ti_s,ti_e (1<=i<=n) representing the start and end times of the first episode. To simplify the problem, each time is represented by a positive integer. N=0 indicates the end of the input. Do not do the processing.
Output for each test instance, outputs the number of TV shows that can be fully seen. One row for each test instance output.
Sample Input
121 33 40 73 815 1915 2010 158 186 125 104 142 90
Sample Output
5
Code:
Import java.util.*;p ublic class main{public static void Main (string[] args) {Scanner cin=new Scanner (system.in); while ( Cin.hasnext ()) {int n=cin.nextint (); if (n==0) break;else{int a[][]=new int[2][n];for (int i=0;i<n;i++) {a[0][i]= Cin.nextint (); A[1][i]=cin.nextint ();} for (int i=0;i<n-1;i++) {for (int j=i+1;j<n;j++) {if (a[1][i]>a[1][j]) {int t=a[0][i];a[0][i]=a[0][j];a[0][j]= T;int c=a[1][i];a[1][i]=a[1][j];a[1][j]=c;}}} int s;int count=1;s=a[1][0];for (int i=1;i<n;i++) {if (a[0][i]>=s) {count++;s=a[1][i];}} System.out.println (count);}}}
HDU 2037 this summer does not AC (Java)