forked from codereport/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path101Hack54_P2.cpp
More file actions
52 lines (41 loc) · 1.38 KB
/
Copy path101Hack54_P2.cpp
File metadata and controls
52 lines (41 loc) · 1.38 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
// code_report Solution
// https://youtu.be/OZXNM0qK17A
#include <vector>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
using ld = long double;
ld time_to_end (ld pos, ld stop, ld last_stop, ld v, ld t, ld w, ld s)
{
ld walk_time = abs (pos - stop) / s;
ld time_arrive_at_stop = t + walk_time;
ld bus_arrival_offset = stop / v;
ld bus_number = max ((ld) 0, ceil ((time_arrive_at_stop - bus_arrival_offset) / w));
ld time_get_on_bus = bus_number * w + bus_arrival_offset;
ld time_on_bus = (last_stop - stop) / v;
return time_get_on_bus + time_on_bus;
}
void solve (vector<ld> stops, ld w, ld v, ld q)
{
while (q--) {
ld pos, t, s;
cin >> pos >> t >> s;
auto ans = numeric_limits<ld>::max ();
auto it = upper_bound (stops.begin (), stops.end (), pos);
if (it != stops.end ()) ans = min (ans, time_to_end (pos, *it, stops.back (), v, t, w, s));
if (it != stops.begin ()) ans = min (ans, time_to_end (pos, *prev (it), stops.back (), v, t, w, s));
ans = min (ans, (stops.back () - pos) / s + t);
cout << fixed << setprecision (10) << ans << endl;
}
}
int main ()
{
int n, q; cin >> n;
vector<ld> stops (n);
for (int i = 0; i < n; ++i) cin >> stops[i];
ld w, v; cin >> w >> v >> q;
solve (stops, w, v, q);
return 0;
}