| 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 + +)