Sort Training 5 D-4

Source: Internet
Author: User

"This summer vacation is not AC?" ”
Yes ”
"Then what do you do?" ”
"Watch the World Cup, you idiot!" ”
"@#$%^&*% ..."

Indeed, the World Cup has come, the fans of the festival has come, it is estimated that many acmer will also throw away the computer, to the TV.
As fans, must want to see as much as possible complete game, of course, as a new era of good youth, you will certainly see some other programs, such as news broadcast (never forget about the state of affairs), very 6+7, Super girls, and Wang Xiao Ya's "Happy Dictionary" and so on, If you already know the schedule of all the TV shows you like to watch, will you make reasonable arrangements? (The goal is to be able to see as many full programs as possible)

Input

The input data contains multiple test instances, and the first line of each test instance has only one integer n (n<=100), representing the total number of shows you like to see, followed by n rows of data, each row containing two data ti_s,ti_e (1<=i<=n), Represents the start and end times of the I program, respectively, in order to simplify the problem, each time is represented by a positive integer. N=0 indicates that the input is finished and not processed.

Output

For each test instance, the output is the number of TV shows that can be fully seen, and the output for each test instance is one row.

Sample Input

121 33 40 73 815 1915 2010 158 186 125 104 142 90

Sample Output

5

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace Std;
struct TIME
{
int s,e;
}T[10000];
BOOL Cmp1 (time A,time B)
{
if (A.S==B.S)
Return a.e<b.e;
Return a.s<b.s;
}
int main ()
{
int n,i;
while (~SCANF ("%d", &n))
{
if (n==0) continue;
for (i=0;i<n;i++)
scanf ("%d%d", &T[I].S,&T[I].E);
Sort (T,T+N,CMP1);
int sum[1000],i1;
for (i1=0;i1<n;i1++)
{
Sum[i1]=1;
int k,j=i1;
for (k=0;k<n;k++)
{
if (T[K].S>=T[J].E)
{
int i2;
J=k;
for (i2=k+1;i2<n-1;i2++)
{
if (T[I2].E<T[J].E) J=i2;
}
sum[i1]++;
Continue
}
}

}
Sort (sum,sum+n);
printf ("%d\n", sum[n-1]);
}
return 0;
}

Experience: Must be careful ....

Sort Training 5 D-4

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.