Ural1203--dpor Greedy--scientific Conference

Source: Internet
Author: User

Description

Functioning of a scientific conference is usually divided into several simultaneous sections. For example, there is a section in parallel computing, a section on visualization, a section on data compression, and So on. Obviously, simultaneous work of several sections are necessary in order-to-reduce the time for scientific program of the CO Nference and to has more time for the banquet, tea-drinking, and informal discussions. However, it's possible that interesting reports be given simultaneously at different sections. A participant have written out the time-table of all the reports which is interesting for him. He asks you to determine the maximal number of reports he'll be able to attend.

Input

The first line contains the number 1≤N≤100000 of interesting reports. Each of the nextNlines contains, integersTsandTeSeparated with a space (1≤Ts<Te≤30000). These numbers is the times a corresponding report starts and ends. Time is measured in minutes from the beginning of the conference.

Output

You should output the maximal number of reports which the participant can attend. The participant can attend no, reports simultaneously and any, reports he attends must be separated by at least one Minute. For example, if a report ends at, the next report which can is attended must begin at + or later.

Sample Input

input Output
53 41 56 74 51 3
3

To find out the maximum number of disjoint intervals

The original source of the transmission door

Greedy:

For all the time to sort the end, because the sooner the end of the more can be added in, each step is the best

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;struct edge{    int b;    int e;} A[100010];bool CMP (Edge I, Edge j) {    if (i.e = = J.E)        return I.B < J.B;    return i.e < J.E;} int main () {    int n;    while (~SCANF ("%d", &n)) {for        (int i = 1; I <= n; i++)            scanf ("%d%d", &A[I].B,&A[I].E);        Sort (a+1,a+n+1,cmp);        int t = 0;        int ans = 0;        for (int i = 1; I  <= n; i++) {            if (a[i].b >= t) {                t = a[i].e + 1;                ans++;            }        }        printf ("%d\n", ans);    }    return 0;}

Dp:

Ural1203--dpor Greedy--scientific Conference

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.