-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirstCircularTour.cpp
More file actions
41 lines (36 loc) · 879 Bytes
/
firstCircularTour.cpp
File metadata and controls
41 lines (36 loc) · 879 Bytes
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
#include<bits/stdc++.h>
using namespace std;
// first circular tour
class petrolPump{
public:
int petrol;
int distance;
};
void naive(vector<int> p, vector<int> d){
int ans = 0, curr_pet = 0, prev_pet = 0;
for(int i = 0; i < p.size(); i++){
curr_pet += (p[i]-d[i]);
if(curr_pet < 0){
ans = i+1;
prev_pet = curr_pet;
curr_pet = 0;
}
}
cout << ((curr_pet+prev_pet) >= 0 ? (ans+1) : -1);
}
// incomplete
void optimal(petrolPump p[], int n){
int start = 0;
int end = 1;
int curr_pet = p[start].petrol - p[start].distance;
while(start != end || curr)
}
int main(){
vector<int> petrol = {4, 8, 7, 4};
vector<int> dist = {6, 5, 3, 5};
petrolPump p[] = {{6, 4}, {3, 6}, {7, 3}};
int n = 3;
// optimal(petrol, dist);
optimal(p, n);
return 0;
}