-
Notifications
You must be signed in to change notification settings - Fork 0
/
teacher.cpp
86 lines (82 loc) · 2.24 KB
/
teacher.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* > File Name: teacher.cpp
* > Author: Jack Kang
* > Mail: kangyijie@xiyoulinux.org
* > Created Time: 2017年10月24日 星期二 22时08分49秒
*/
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAXSIZE = 1000;
const int GETKEY = 0;
const int PUTKEY = 1;
//char *eventType[2] = {"get","put"}; 忘记杂用了
struct Event{
Event(int eventFlag, int objTime, int objKeyId):flag(eventFlag),time(objTime), keyId(objKeyId){}
int flag;
int time;
int keyId;
};
bool compareEvent(const Event &e1, const Event &e2){
if(e1.time < e2.time)
return true;
if(e1.time == e2.time){
if(e1.flag > e2.flag)
return true;
if(e1.flag < e2.flag)
return false;
if(e1.keyId < e2.keyId)
return true;
else
return false;
}
return false;
}
static int FX;
bool func1(const int key)
{
return FX == key;
}
bool func2(const int key)
{
return -1 == key;
}
int main(void)
{
//debug
//todo: aync
vector<Event> taskLine;
vector<int> keys;
int numKey;
int n ;
scanf("%d%d",&numKey, &n);
for(int i = 0; i <= numKey; i++)
keys.push_back(i);
int keyId,getTime,speedTime;
while(n--){
scanf("%d%d%d",&keyId, &getTime, &speedTime);
taskLine.push_back(Event(GETKEY, getTime, keyId));
taskLine.push_back(Event(PUTKEY, getTime+speedTime, keyId));
}
sort(taskLine.begin(), taskLine.end(), compareEvent);
//debug
//for(const auto i : taskLine)
// printf("Event time:%d keyId:%d,type:%s\n",i.time, i.keyId, eventType[i.flag].c_str());
for(typename vector<Event>::iterator ev = taskLine.begin(); ev != taskLine.end(); ev++ ){
FX = ev->keyId;
if(ev->flag == GETKEY){
typename vector<int>::iterator it = find_if(keys.begin(), keys.end(), func1);
*it = -1;
}
if(ev->flag == PUTKEY){
typename vector<int>::iterator it = find_if(keys.begin(), keys.end(), func2);
*it = ev->keyId;
}
}
//for(auto i : keys)
// printf("%d",i);
for(typename vector<int>::iterator i = keys.begin() + 1; i != keys.end(); ++i)
printf("%d ",*i);
}