//会场安排:先按结束时间排序,最先结束的,先安排
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include <algorithm>
using namespace std;
int m, n;
typedef struct Node
{
int b;
int e;
}Node;
Node a[10005];
int total = 0;
void greedySelect();
bool cmp(Node a, Node b)//升序;
{
return a.e < b.e;
}
int main(void)
{
scanf("%d", &m);
while(m--)
{
scanf("%d", &n);
for(int num = 0; num < n; num++)
{
scanf("%d%d", &a[num].b, &a[num].e);
}
sort(a, a+ n, cmp);
total = 1;
greedySelect();
printf("%d\n", total);
}
return 0;
}
void greedySelect()
{
int j = 0;
for(int i = 1; i < n; i++)
{
if(a[i].b > a[j].e)
{
j = i;
total++;
}
}
}
NYOJ14.会场安排
最新推荐文章于 2022-05-06 13:38:45 发布