CCF 公共钥匙盒

#include
#include

using namespace std; 




typedef struct {
int start_time;
int use_time;
int end_time;
int key;
}Teacher;


bool cmp(Teacher a,Teacher b)
{
    return a.key }

int main()
{
    Teacher  teacher[2000];
    int      key[2000];
    int N,K;
 int i,j;

    cin>>N>>K;
    for(i=0;i     {
        cin>>teacher[i].key>>teacher[i].start_time>>teacher[i].use_time;
        teacher[i].end_time=teacher[i].start_time+teacher[i].use_time;
    }
    for(i=1;i<=N;i++)
    {
        key[i]=i;
    }
 for(i=K;i<=1999;i++)
    {
        teacher[i].key=0;
    }

 
    int time=0;
    int MAX=0;
 sort(teacher,teacher+K,cmp);
 
 for(i=0;i   if(MAX    MAX=teacher[i].end_time;


    while(time<=MAX)
    {
        int position=0;
        for(i=0;i             if(teacher[i].end_time==time)
    for(j=1;j<=N;j++)
     if(key[j]!=-1)
      continue;
      else
     {
      key[j]=teacher[i].key;
      break;
     }

        for(i=0;i             if(teacher[i].start_time==time)
                for(j=1;j<=N;j++)
                    if(key[j]==teacher[i].key)
                        key[j]=-1;
     time++;
    }
    for(i=1;i         cout<  cout<     return 0;
}


你可能感兴趣的:(CCF 公共钥匙盒)