forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA.cpp
More file actions
86 lines (80 loc) · 1.73 KB
/
A.cpp
File metadata and controls
86 lines (80 loc) · 1.73 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
83
84
85
86
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
class walkway {
public:
int b, e, w, d;
walkway(int bb, int ee, int ww) : b(bb), e(ee), w(ww) {
d = e - b;
}
};
bool cmp1(walkway w1, walkway w2) {
return w1.b < w2.b;
}
bool cmp2(walkway w1, walkway w2) {
return w1.w < w2.w;
}
void run() {
int X, S, R, t, N;
cin >> X >> S >> R >> t >> N;
vector<walkway> mm;
REP(i,N) {
int B, E, w;
cin >> B >> E >> w;
mm.push_back(walkway(B, E, w + S));
}
sort(mm.begin(), mm.end(), cmp1);
int len = mm.size();
if (mm[0].b > 0) {
mm.push_back(walkway(0, mm[0].b, S));
}
int next = 0;
REP(i,len) {
if (i == len - 1) next = X;
else next = mm[i + 1].b;
if (mm[i].e < next) {
mm.push_back(walkway(mm[i].e, next, S));
}
}
sort(mm.begin(), mm.end(), cmp2);
double ret = 0.0, tmp = t;
REP(i,mm.size()) {
double dd = mm[i].d;
double ts = mm[i].w + R - S;
double tt = dd / ts;
if (tt >= tmp) {
ret += tmp;
ret += (dd - ts * tmp) / mm[i].w;
tmp = 0;
} else {
ret += tt;
tmp -= tt;
}
}
cout << setprecision(9) << ret << endl;
}
int main() {
int kase;
cin >> kase;
FOR(k,1,kase) {
cout << "Case #" << k << ": ";
run();
}
return 0;
}