Venue arrangement Questions

Source: Internet
Author: User
Tags time limit

Venue Scheduling issues time limit: Ms | Memory limit: 65535 KB Difficulty: 4 Description The school's small auditorium has a lot of activities every day, there is time to plan the time of these activities conflict, you need to choose some activities to organize. Xiao Liu's job is to arrange the activities of the school chapel, with a maximum of one event per time. Now Xiao Liu has some schedule of activities, he would like to arrange as many activities as possible, ask him how to arrange.
The input first line is an integer number M (m<100) representing a total of M-Group test data.
The first line of each set of test data is an integer n (1<n<10000) that indicates that there are n activities in the test data.
Subsequent n rows, each line having two positive integers bi,ei (0<=bi,ei<10000), representing the start and end time of the first activity (BI<=EI)
Outputs the maximum number of activities that can be scheduled for each set of inputs.
Output of each group takes one line sample input

2
2
1,
3 1,
11 20
Sample output
1
2

<span style= "FONT-FAMILY:SIMSUN;FONT-SIZE:18PX;"   > #include <stdio.h> #include <stdlib.h> struct node {int s;   Start time int t;
End time};
Node a[10001];
    int cmp (const void *a,const void *b) {node *c = (node *) A;
    Node *d = (node *) b;
    if (c->t>d->t) {return 1;
    } else {return-1;
    }} int main () {int m,n,i,ans,tmp;
    scanf ("%d", &m);
        while (m--) {scanf ("%d", &n);
        if (n==0) {printf ("0\n"); } else {for (i=0;i<n;i++) {scanf ("%d%d", &a[i].s,&a[i].
            T);
            } qsort (A,n,sizeof (a[0]), CMP);//end time from small to large sort tmp=0;
            Ans=1;
                for (i=1;i<n;i++) {if (a[i].s>a[tmp].t)//Take the second start time to start and the first end time to compare more than start plus, and place a note
                    {ans++;
                Tmp=i;
}
            }            printf ("%d\n", ans);
}} return 0;
 }</span>


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.