Venue arrangement problem (Greedy Algorithm)
Venue Schedule Problem time limit: 3000 MS | memory limit: 65535 KB difficulty: 4
-
Description
-
There are many activities in the auditorium of the school every day. The scheduled time for these activities may conflict, and you need to select some activities to hold. Xiao Liu's job is to arrange activities in the school auditorium. at most one activity can be arranged at a time. Now Mr. Liu has some schedules for his activities. He wants to arrange as many activities as possible. How can he arrange them.
-
Input
-
The first row is an integer m (m <100), indicating a total of m groups of test data.
The first row of each group of test data is an integer n (1 Next n rows, each row has two positive integers Bi, Ei (0 <= Bi, Ei <10000), indicating the start time and end time of the I-th activity (Bi <= Ei)
-
Output
-
For each group of inputs, the maximum number of activities that can be arranged is output.
Output of each group occupies one row
-
Sample Input
-
221 1010 1131 1010 1111 20
-
Sample output
-
12
#include
#include#include
using namespace std;struct mad{int s;int e;}t[10002];bool cmp(struct mad c,struct mad d){ return c.e
>n;while(n--){int i,count=1,m;cin>>m;for(i=0;i
>t[i].s>>t[i].e;sort(t,t+m,cmp);int end=t[0].e;for(i=1;i