版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40475529/article/details/82597716
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct br
{
int num,begin,end;
} b[1010];
int a[1010];
bool cmpb(const br &a,const br &b)
{
return a.begin<b.begin;
}
bool cmpe(const br &a,const br &b)
{
return a.end==b.end?a.num<b.num:a.end<b.end;
}//定义比较函数
int main()
{
int n,k;
cin>>n>>k;
for(int i=0; i<k; i++)
{
int x;
cin>>b[i].num>>b[i].begin>>x;
b[i].end=x+b[i].begin;
}
for(int i=0; i<n; i++)
a[i]=i+1;
sort(b,b+k,cmpb);
int time1=b[0].begin;
sort(b,b+k,cmpe);
int time2=b[k-1].end;
for(int t=time1; t<=time2; t++)
{
for(int i=0; i<k; i++)
{
if(b[i].end==t)
{
for(int j=0; j<n; j++)
if(a[j]==0)
{
a[j]=b[i].num;
break;
}
} //还钥匙
if(b[i].begin==t)
{
for(int j=0; j<n; j++)
if(a[j]==b[i].num) a[j]=0;
}//取钥匙
}
}
for(int i=0; i<n; i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
模拟题:思路是先找出最大最小时间,对时间遍历,对取钥匙还钥匙进行操作,足够
细心就不难