-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashcode.cpp
More file actions
156 lines (140 loc) · 3.93 KB
/
hashcode.cpp
File metadata and controls
156 lines (140 loc) · 3.93 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include<bits/stdc++.h>
using namespace std;
class contributor{
public:
string name;
vector < pair <string, int> > skillset;
contributor(string name, vector <pair <string, int> > &skillset){
this->name = name;
this->skillset = skillset;
}
};
class project{
public:
string name;
int score;
int reqDays;
int bestBefore;
vector < pair <string, int> > skillset;
project(string name, int reqDays, int score, int Bestbefore, vector <pair <string, int> > &skillset){
this->name = name;
this->reqDays = reqDays;
this->score = score;
this->bestBefore = bestBefore;
this->skillset = skillset;
}
};
bool operator < (project & p1, project & p2){
return p1.reqDays * p2.score < p2.reqDays * p1.score;
}
int find(vector <contributor> & list, bool * visited, pair<string, int> & j){
int pos = 0;
for(auto x:list){
if (visited[pos] == true) {
pos ++;
continue;
}
for(auto &y : x.skillset){
if(y.first != j.first) continue;
if (y.second >= j.second) {
if (y.second == j.second) y.second++;
visited[pos] = true;
return pos;
}
}
pos ++;
}
return -1;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("d_dense_schedule.in.txt", "r", stdin);
freopen("outputd.txt", "w", stdout);
#endif
//input
int contributorCnt;
int projCnt;
cin >> contributorCnt;
cin >> projCnt;
vector <contributor> contList;
vector <project> projList;
for (int i = 0; i < contributorCnt; i++){
string name;
int skillCount;
vector <pair <string , int> > temp;
cin >> name;
cin >> skillCount;
for(int j = 0; j < skillCount; j++){
string skillName;
int skillLevel;
cin >> skillName;
cin >> skillLevel;
temp.push_back(pair <string, int>(skillName, skillLevel));
}
contList.push_back(contributor(name, temp));
}
for(int i = 0; i < projCnt; i++){
string name;
cin >> name;
int reqDays;
cin >> reqDays;
int score;
cin >> score;
int bestBefore;
cin >> bestBefore;
int skillCount;
cin >> skillCount;
vector <pair <string, int> > temp;
for(int j = 0; j<skillCount; j++){
string skillName;
int skillLevel;
cin >> skillName;
cin >> skillLevel;
temp.push_back(pair <string, int>(skillName, skillLevel));
}
projList.push_back(project(name, reqDays, score, bestBefore, temp));
}
sort(projList.begin(), projList.end());
//input end
//vector before showing output
//res: stores list of Project outputs
//restemp: stores string list (starts with proj name and followed by contr names)
vector <vector <string> > res;
bool visited[contributorCnt] = {false};
vector <string> resTemp;
bool flag = false;
for(int i = 0; i<projCnt; i++){
resTemp.clear();
resTemp.push_back(projList[i].name);
for(auto j : projList[i].skillset){
int pos = find(contList, visited, j);
if (pos == -1) {
flag = true;
vector <string> clear;
resTemp= clear;
break;
}
else resTemp.push_back(contList[pos].name);
}
if (flag == true){
flag = false;
} else {
res.push_back(resTemp);
}
for(int i = 0; i<contributorCnt; i++){
visited[i] = false;
}
}
cout << res.size() << endl;
for (auto x:res){
bool flag = true;
for(auto y:x){
cout << y;
if (flag == true){
cout << endl;
} else cout << " ";
flag = false;
}
cout << endl;
}
}