This repository has been archived by the owner on Jan 12, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
245 lines (169 loc) · 4.24 KB
/
main.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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cstdlib>
struct Input
{
int R; /* horizontal rows */
int C; /* vertical columns */
int F; /* vechicles */
int N; /* number of prebooked rides */
int B; /* bonus */
int T; /* simulation steps */
} input;
struct Int2
{
int x = 0;
int y = 0;
};
struct Ride
{
int ID;
Int2 start_intersection;
Int2 finish_intersection;
int earliest_start;
int latest_finish;
int real_start;
int points() const
{
return finish_intersection.x - start_intersection.x + finish_intersection.y - start_intersection.y;
}
int dist(Int2 a, Int2 b)
{
return abs(a.x - b.x) + abs(a.y - b.y);
}
bool canTake();
};
struct
{
bool operator() (const Ride& a, const Ride& b) const
{
return a.points() > b.points();
}
} rideComparer;
struct
{
bool operator() (const Ride& a, const Ride& b) const
{
return a.real_start > b.real_start;
}
} rideComparerStart;
struct Vehicle
{
std::vector<Ride> rides;
};
bool Ride::canTake()
{
// Vehicle current_vehicle = vehicles[currentVehicleID];
// for (int i = 0; i < current_vehicle.rides.size()) {
// checkedRide = current_vehicle.rides[i];
// if (checkedRide.latest_finish )
// }
return true;
} // jak chcesz commitować to zakomentuj po prostu
std::vector<Ride> rides;
std::vector<Vehicle> vehicles;
int currentVehicleID = 0;
/* initialized input data and structures */
void initialize(const std::string path)
{
std::ifstream file{ path };
/* initial parameters */
file >> input.R;
file >> input.C;
file >> input.F;
file >> input.N;
file >> input.B;
file >> input.T;
/* create vehicles */
for (int i = 0; i < input.F; ++i)
{
vehicles.emplace_back();
}
/* create rides */
for (int i = 0; i < input.N; ++i)
{
Ride ride;
file >> ride.start_intersection.x;
file >> ride.start_intersection.y;
file >> ride.finish_intersection.x;
file >> ride.finish_intersection.y;
file >> ride.earliest_start;
file >> ride.latest_finish;
ride.ID = rides.size();
rides.push_back(ride);
}
file.close();
}
/* saves output data */
void submit(const std::string& path)
{
std::ofstream output;
output.open(path.c_str());
if (output.is_open())
{
for (int i = 0; i < vehicles.size(); i++)
{
output << vehicles[i].rides.size() << " ";
for (int j = 0; j < vehicles[i].rides.size(); j++)
{
output << vehicles[i].rides[j].ID << " ";
}
output << std::endl;
}
}
output.close();
}
void calculate()
{
while (!rides.empty())
{
// sort rides by how good they are, best ones first
std::cout << "sorting rides...";
std::sort(rides.begin(), rides.end(), rideComparer);
std::cout << "sorted" << std::endl;
// pick the first ride which we can take at all
std::cout << "iterating rides..." << std::endl;
for (int i = 0; i < rides.size(); i++)
{
std::cout << "\tchecking ride with ID " << rides[i].ID << "..." << std::endl;
if (rides[i].canTake())
{
std::cout << "\t\ttaking ride" << std::endl;
for (int j = 0; j < vehicles[currentVehicleID].rides.size(); j++)
{
if (vehicles[currentVehicleID].rides[i].end() > )
rides[i].real_start
}
vehicles[currentVehicleID].rides.push_back(rides[i]);
std::sort(vehicles[currentVehicleID].rides.begin(), vehicles[currentVehicleID].rides.end(), rideComparerStart);
rides.erase(rides.begin() + i);
break;
}
}
std::cout << "iterated" << std::endl;
currentVehicleID++;
}
}
int main(int argc, const char* argv[])
{
std::string input_file, output_file;
if (argc == 3)
{
input_file = argv[1];
output_file = argv[2];
}
else
{
std::cout << "Usage: pieczarki [file_name.in] [file_name.out]" << std::endl;
std::cout << "Assuming files are a_example.*" << std::endl;
input_file = "a_example.in";
output_file = "a_example.out";
}
initialize(input_file);
calculate();
submit(output_file);
return 0;
}