-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch_time_prior.cpp
78 lines (69 loc) · 2.41 KB
/
search_time_prior.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
#include <bits/stdc++.h>
#include "burrito_extras.h"
#include "calc_score.h"
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
bool operator <(const Order& a, const Order& b) {
return stoi(a.time.substr(2, 2)) > stoi(b.time.substr(2, 2));
}
bool operator >(const Order& a, const Order& b) {
return stoi(a.time.substr(2, 2)) < stoi(b.time.substr(2, 2));
}
int main() {
string time;
int tmp_index, curr;
double lat, lon, dist_shop, dist, tmp_min;
vector<Coordinate> pos_vec;
vector<Order> out_vec;
vector<Order> order_vec;
vector<bool> used;
used.reserve(100);
vi final_index_vec;
priority_queue<Order> time_q;
vector<Order> passed_orders;
float ct = 0, score = 0;
Coordinate cl = Coordinate(53.38195, -6.59192);
for (int i=0;i<100;i++) {
cin >> lat >> lon >> time;
pos_vec.push_back(Coordinate(lat, lon));
order_vec.push_back(Order(lat, lon, time, i));
time_q.push(Order(lat, lon, time, i));
}
while (!time_q.empty()) {
if (time_q.top().achievable(ct, cl)) {
out_vec.push_back(time_q.top()); // put on out_vec
ct += time_q.top().time_to_get(cl); // update current time and current location
cl = time_q.top().location;
cerr << time_q.top().index << endl; // keeping a current for the exiting the loop
curr = time_q.top().index;
used[time_q.top().index] = true;
time_q.pop();
} else {
passed_orders.push_back(time_q.top());
time_q.pop();
}
}
cerr << "Switching" << endl;
while(out_vec.size() < 100) {
tmp_min = INF;
for (int j=0;j<passed_orders.size();j++) {
if (j!=curr) {
dist = HaversineDistance(passed_orders[curr].location, passed_orders[j].location);
if (!used[passed_orders[j].index] && dist < tmp_min) {
tmp_min = dist;
tmp_index = passed_orders[j].index;
}
}
}
used[tmp_index] = true;
out_vec.push_back(order_vec[tmp_index]);
curr = tmp_index;
cerr << curr << endl;
}
cout << calc(out_vec) << endl;
for(Order o : out_vec) cout << o.index << ",";cout << endl;
}