今天做一个微软的校招笔试题 Registration Day ,用优先队列模拟操作的。粘贴来别人的代码,谨记 pq 的用法。另外 memset 包含在 string.h 里。
1 #include <stdio.h> 2 #include <string.h> 3 #include <limits.h> 4 #include <queue> 5 #include <vector> 6 #include <set> 7 #include <map> 8 #include <algorithm> 9 10 using namespace std; 11 12 int N, M, K; 13 struct Student 14 { 15 int id; 16 int arrive_time; 17 int office_num; 18 int finish_time; 19 std::vector<pair<int, int> > register_offices; 20 }; 21 Student students[10005]; 22 struct Event 23 { 24 int student_idx; 25 int office; 26 int begin; 27 int duration; 28 Event(int s, int o, int b, int d): student_idx(s), office(o), begin(b), duration(d){}; 29 }; 30 struct Cmp 31 { 32 bool operator()(const Event &e1, const Event &e2){ 33 if (e1.begin == e2.begin) 34