HDU 2037

//题目类型:贪心中的纯活动安排问题,
#include <cstdlib>
#include <algorithm>
#include <iostream>
//#include <conio.h>
using namespace std;
#define arraysize 101
typedef struct time
{
    int start;
    int finish;
}activity;
activity activitys[arraysize];
bool final[arraysize];
int n;
bool cmp(activity a,activity b)
{
     return a.finish<b.finish;
}
void Greedy()
{
     int count = 1;
     int i,j = 1;
     final[1] = true;
     for(i=2;i<n+1;++i)
     {
         if(activitys[i].start>=activitys[j].finish)
         {
             count++;
             j = i;
             final[j] = true;
         }        
     }
     cout<<count<<endl;
}
int main(int argc, char *argv[])
{
    int i,j;
    int start,end;
    //freopen("1.txt","r",stdin);
    while(cin>>n)
    {
        if(n==0)
            break;
        for(i=1;i<n+1;++i)
        {
            cin>>start>>end;
            activitys[i].start = start;
            activitys[i].finish = end;
        }
        sort(activitys+1,activitys+n+1,cmp);
        memset(final,0,sizeof(final));
        Greedy();
    }
    //getch();
    system("PAUSE");
    return EXIT_SUCCESS;
}

你可能感兴趣的:(HDU)