AcWing 3248. 公共钥匙盒
原题链接
简单
作者:
把这题Ac了
,
2024-12-01 16:29:49
,
所有人可见
,
阅读 1
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef pair<int,int> PII;
const int N = 1010;
int key[N],st[N],max_time,te_st[N];
struct node{
int l,r,key;
}te[N];
int n,m;
bool cmp(node &a,node &b){
if(a.key != b.key) return a.key < b.key;
return a.l < b.l;
}
int find_ept(){
for(int i = 1;i <= n;i++)
if(st[i]) return i;
}
int find_is(int val){
for(int i = 1;i <= n;i++)
if(key[i] == val) return i;
}
int main(){
cin >> n >> m;
for(int i = 1;i <= n;i++) key[i] = i;
for(int i = 1;i <= m;i++){
int w,s,c;
cin >> w >> s >> c;
max_time = max(max_time,s + c);
te[i] = {s,s + c,w};
}
sort(te + 1,te + 1 + m,cmp);
for(int i = 1;i <= max_time;i++){
for(int j = 1;j <= m;j++){
if(!te_st[j]){
//归还
if(te[j].r == i){
te_st[j] = 1;
int idx = find_ept();
key[idx] = te[j].key;
st[idx] = 0;
}
}
}
//取钥匙
for(int j = 1;j <= m;j++){
if(!te_st[j]){
if(te[j].l == i){
int idx = find_is(te[j].key);
st[idx] = 1;
}
}
}
//取钥匙
}
for(int i = 1;i <= n;i++)
cout << key[i] << ' ';
return 0;
}