Active selection (c + +)

Source: Internet
Author: User

activity selection
difficulty level: C; run time limit: 500ms; run empty Limit: 51200KB; code length limit: 2000000B
question description

    schools have n events in the last few days, and these activities all require To use the school auditorium, at the same time, the auditorium can only be used by one activity. Because of the conflict in some activities, the school office staff had to let some activities abandon the use of the auditorium instead of the classroom.

    now gives the starting time Begini and end time for n events to use the auditorium Endi, please help the office staff to arrange some activities to use the auditorium, so that the planned activities as much as possible.

input
first row an integer n.
Next n rows, 2 integers per line, first Begini, and second Endi.
output
The maximum number of activities that can be scheduled.
Input Example
11
3 5
1 4
12 14
8&N bsp;12
0 6
8 11
6 10
5 7
3 8
5 9
2 13
Output Sample
4
Other instructions
1<=n<=1000,begini<= endi<=32767
Scx Writing

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace Std;
struct SS
{
int x, y;
}P[1010];
BOOL CMP (SS A,ss B)
{
if (A.Y!=B.Y) return a.y<b.y;
else if (a.x!=b.x) return a.x<b.x;
}
int main ()
{
int n;
while (scanf ("%d", &n)!=eof)
{
int i;
for (i=0;i<n;i++)
scanf ("%d%d", &p[i].x,&p[i].y);
Sort (p,p+n,cmp);
int a=p[0].y,cnt=1;
for (i=1;i<n;i++)
if (a<=p[i].x)
{
cnt++;
A=P[I].Y;
}
printf ("%d\n", CNT);
}
return 0;
}

Active selection (c + +)

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.