2892:i--free to watch moviesTime limit:1 Sec Memory limit:128 MB
Submit:22 solved:10
[Submit] [Status] [Web Board]
Description
Vientiane City Star U.S. cinema opening 1 years, to hold a one-day big bargain, the ACM players ready to go to the movies. Known cinemas play at various stages of the movie. Ask the ACM team how to arrange their own time, so that the number of movies to see the most. Input
Test data first behavior N (n>=0), which represents the number of movies, followed by n rows, each row has two integers, indicating the start and end time of each movie. Output
Output the maximum number of films that the ACM can watch. Sample Input
A
8 of
16 20 in a-one-and-a-list
Sample Output
5
HINT
Source
LDF
AC Code:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
struct movie{
int bg;
int en;
};
Movie my[111];
BOOL Comp (movie A,movie b) {
if (a.bg!=b.bg) return a.en<b.en;
Return a.bg<b.bg;
}
int main () {
int n;
cin>>n;
int i;
for (i=0;i<n;++i) {
cin>>my[i].bg>>my[i].en;
}
Sort (my,my+n,comp);
/**
cout<< ' \ n ';
for (i=0;i<n;++i) cout<<my[i].bg<< ' <<my[i].en<< ' \12 ';
cout<< ' \ n ';
/**/
int sum=1,t;
T=my[0].en;
for (i=0;i<n;++i) {
if (t<=my[i].bg) {
sum++;
T=my[i].en
}
}
if (n==0) sum=0;
cout<<sum<< ' \12 ';
return 0;
}
LDF