Skip to content

Commit

Permalink
added galaxy taxes
Browse files Browse the repository at this point in the history
  • Loading branch information
aajjbb committed Jun 22, 2016
1 parent 23e95a7 commit 9ccdd93
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 31 deletions.
116 changes: 116 additions & 0 deletions LiveArchive/GalaxyTaxes.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include <bits/stdc++.h>

template<typename T> T gcd(T a, T b) {
if(!b) return a;
return gcd(b, a % b);
}
template<typename T> T lcm(T a, T b) {
return a * b / gcd(a, b);
}

template<typename T> void chmin(T& a, T b) { a = (a > b) ? b : a; }
template<typename T> void chmax(T& a, T b) { a = (a < b) ? b : a; }
int in() { int x; scanf("%d", &x); return x; }

using namespace std;

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

typedef long long Int;
typedef unsigned long long uInt;
typedef unsigned uint;

const int MAXN = 1010;
const double INF = 100010100100100100.0;

int N, M;
double dist[MAXN];
vector<pair<int, pair<int, int> > > G[MAXN];

double getDist(double tempo) {
priority_queue<pair<double, int> > q;
q.push(make_pair(0, 1));

for (int i = 0; i < MAXN; i++) {
dist[i] = INF;
}

dist[1] = 0;

while (!q.empty()) {
double curr_dist = -q.top().first;
int now = q.top().second;
q.pop();

if (curr_dist > dist[now]) continue;

if (now == N) {
break;
}

for (int i = 0; i < (int) G[now].size(); i++) {
int next = G[now][i].first;
double next_dist = dist[now] + G[now][i].second.first * tempo + G[now][i].second.second;

if (dist[next] > next_dist) {
dist[next] = next_dist;
q.push(make_pair(-next_dist, next));
}
}
}

return dist[N];
}

int main(void) {
while (cin >> N >> M) {
for (int i = 0; i < MAXN; i++) {
G[i].clear();
}
for (int i = 0; i < M; i++) {
int A, B, P, Q;
cin >> A >> B >> P >> Q;

G[A].push_back(make_pair(B, make_pair(P, Q)));
G[B].push_back(make_pair(A, make_pair(P, Q)));
}

double l = 0, h = 24 * 60;
double best = max(getDist(0), getDist(24 * 60));

for (int x = 0; x < 100; x++) {
double ll = l + (h - l) / 3.0;
double hh = h - (h - l) / 3.0;

double dl = getDist(ll);
double dh = getDist(hh);

//cout << fixed << setprecision(5) << ll << " " << hh << " " << dl << " " << dh << endl;

best = max(best, max(dl, dh));

double sl = INF;
double sh = INF;

for (int i = 0; i < N; i++) {
for (int j = 0; j < (int) G[i].size(); j++) {
sl = min(sl, G[i][j].second.first * ll + G[i][i].second.second);
sh = min(sh, G[i][j].second.first * hh + G[i][i].second.second);
}
}

if (dl < dh) {
l = ll;
} else {
h = hh;
}
}

cout << fixed << setprecision(5) << best << "\n";
}
return 0;
}
54 changes: 23 additions & 31 deletions LiveArchive/i.in
Original file line number Diff line number Diff line change
@@ -1,31 +1,23 @@
2
3 3 10
A 2
B 2
C 3
AA 10
AAA 30
ABC 60
14 8 200
M 2
I 3
R 2
A 1
O 2
E 2
C 2
L 2
F 1
V 2
Y 3
H 1
U 2
N 2
MIRACLE 100
FLUFFY 40
LOVE 100
IVY 10
VEN 30
AYE 20
HOE 10
EURO 80
2 1
1 2 1 0
5 8
1 2 27 610658
2 3 -48 529553
3 4 -6 174696
4 5 47 158238
3 5 84 460166
1 3 -21 74502
2 4 -13 858673
1 5 -90 473410
3 3
1 2 1 0
2 3 1 0
1 3 -1 1440
4 5
1 2 1 0
2 4 2 0
1 4 0 500
1 3 -1 1440
3 4 -2 2880
2 1
1 2 0 0

0 comments on commit 9ccdd93

Please sign in to comment.