-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuva11935.cpp
More file actions
82 lines (75 loc) · 2.43 KB
/
uva11935.cpp
File metadata and controls
82 lines (75 loc) · 2.43 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
/* Rishikesh
* UVA 11935
* Through the Desert
* This problem is classified as binary search problem in
* Halim's CP3 book. It can be done in one simulation of the race.
* You have to keep track of fuel used until one reaches a gas station
* or the goal.
*/
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cstdint>
#include<numeric>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<bitset>
using namespace std;
int main() {
string s;
vector<double> fuelconsumed(1); //Keeps track of fuel needed till the next gas station of the goal
int fuelconsumption;
int leaks = 0, prevmarker = 0;
int when;
string what;
while (true) {
getline(cin, s);
auto iss = istringstream(s);
iss >> when >> what;
if (what == "Goal") {
if (when > 0) {
fuelconsumed.back() += double(when - prevmarker)*fuelconsumption/100.0 +
(when - prevmarker) * leaks;
}
printf("%0.3f\n", *max_element(fuelconsumed.begin(), fuelconsumed.end()));
fuelconsumed.resize(1); fuelconsumed = {0};
prevmarker = 0;
fuelconsumption = 0;
leaks = 0;
} else if (what == "Fuel") {
if (when > 0) {
fuelconsumed.back() += double(when - prevmarker)*fuelconsumption/100.0 +
(when - prevmarker) * leaks;
prevmarker = when;
}
iss >> what;
iss >> fuelconsumption;
prevmarker = when;
if (fuelconsumption == 0)
break;
} else if (what == "Leak") {
fuelconsumed.back() += double(when - prevmarker)*fuelconsumption/100.0 +
(when - prevmarker) * leaks;
prevmarker = when;
leaks++;
} else if ( what == "Mechanic") {
fuelconsumed.back() += double(when - prevmarker)*fuelconsumption/100.0 +
(when - prevmarker) * leaks;
prevmarker = when;
leaks = 0;
} else if (what == "Gas" ) {
fuelconsumed.back() += double(when - prevmarker)*fuelconsumption/100.0 +
(when - prevmarker) * leaks;
prevmarker = when;
fuelconsumed.push_back(0); //add a new fuel counter at the end of the vector
}
}
}