Ytu 2892 free Watch movie greedy

Source: Internet
Author: User


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

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.