问题描述
假设要在足够多的会场里安排一批活动,并希望使用尽可能少的会场。设计一个算法进行安排。
测试用例:
5(活动数目)
1 23
12 28
25 35
27 80
36 50
输出:3
贪心
#include<stdio.h>
#define n 5
int a[n][2]={{1,23},{12,28},{25,35},{27,80},{36,50}};
int tag[n];
int count=0;
int main()
{
int i,j,temp;
for(i=0;i<n;i++)
{
tag[i]=0;
}
for(i=0;i<n;i++)
{
if(tag[i])
continue;
temp=a[i][1];
printf("%d\t",i+1);
for(j=i+1;j<n;j++)
{
if(tag[j])
continue;
if(temp<a[j][0])
{
tag[j]=1;
temp=a[j][1];
printf("%d\t",j+1);
}
}
printf("\n======================\n");
count++;
}
printf("the count is %d\n",count);
return 0;
}