-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aajjbb
committed
May 27, 2015
1 parent
a91709c
commit c9e5316
Showing
32 changed files
with
3,004 additions
and
55 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,2 @@ | ||
<<<<<<< HEAD | ||
4 4 | ||
1 2 6 3 | ||
3 5 3 1 | ||
1 2 | ||
2 3 | ||
3 4 | ||
4 2 | ||
======= | ||
2 1 4 | ||
1 5 3 | ||
3 3 10 | ||
7 10 2 | ||
6 4 8 | ||
>>>>>>> a0ebb3d2a55154c2494fd954284990999378d20b | ||
10 | ||
1 2 3 4 5 4 3 2 1 6 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#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; | ||
|
||
typedef long long Int; | ||
typedef unsigned uint; | ||
|
||
const int MAXN = 555; | ||
const int MAXL = 601*481 + 10; | ||
const int INF = 10101011; | ||
|
||
int N, M; | ||
vector<int> graph[MAXN]; | ||
vector<pair<pair<int, int>, int> > info[MAXN][MAXN]; | ||
int dist[MAXL]; | ||
int stim[MAXL]; | ||
|
||
struct state { | ||
int id, charge, daytime; | ||
int code; | ||
|
||
state(){} | ||
|
||
state(int id, int charge, int daytime): id(id), charge(charge), daytime(daytime) { | ||
this->code = this->id * 481 + this->charge; | ||
} | ||
|
||
bool operator<(const state other) const { | ||
return dist[code] > dist[other.code]; | ||
} | ||
}; | ||
|
||
/* | ||
Exemplo 1: (0 - 1) => 100 | ||
(1 - 3) => 75 + (5 min de espera) | ||
Exemplo (570) : (0 - 1) => 200 | ||
: (1 - 3) => 570 (300) | ||
*/ | ||
|
||
int main(void) { | ||
while (cin >> N >> M && !(N == 0 && M == 0)) { | ||
int A, B, X, Y, Z; | ||
|
||
for (int i = 0; i < MAXN; i++) { | ||
graph[i].clear(); | ||
for (int j = 0; j < MAXN; j++) { | ||
info[i][j].clear(); | ||
} | ||
} | ||
for (int i = 0; i < M; i++) { | ||
cin >> A >> B; | ||
graph[A].push_back(B); | ||
graph[B].push_back(A); | ||
|
||
while (1) { | ||
cin >> X >> Y >> Z; | ||
|
||
if (Z <= 280) { | ||
info[A][B].push_back(make_pair(make_pair(X, Y), Z)); | ||
info[B][A].push_back(make_pair(make_pair(X, Y), Z)); | ||
} | ||
if (Y == 1439) break; | ||
} | ||
} | ||
|
||
int ans = INF; | ||
priority_queue<state> q; | ||
state base = state(0, 480, 720); | ||
|
||
q.push(base); | ||
|
||
memset(dist, 63, sizeof(dist)); | ||
memset(stim, 63, sizeof(stim)); | ||
|
||
dist[base.code] = 0; | ||
stim[base.code] = 0; | ||
|
||
for ( ; !q.empty(); ) { | ||
state now = q.top(); | ||
q.pop(); | ||
|
||
if (dist[now.code] > ans) continue; | ||
|
||
//cout << now.id << " " << now.charge << " " << now.daytime << " => " << dist[now.id][now.daytime] << "\n"; | ||
|
||
if (now.id == N - 1) { | ||
chmin(ans, dist[now.code]); | ||
} | ||
|
||
for (int i = 0; i < (int) graph[now.id].size(); i++) { | ||
int next = graph[now.id][i]; | ||
|
||
for (int k = 0; k < (int) info[now.id][next].size(); k++) { | ||
int si = info[now.id][next][k].first.first; | ||
int ed = info[now.id][next][k].first.second; | ||
int tt = info[now.id][next][k].second * 2; | ||
|
||
int wait_time = max(0, tt - now.charge); | ||
int next_daytime = (stim[now.code] + wait_time) % 1440; | ||
|
||
if (next_daytime > ed) { | ||
wait_time += 1440 - next_daytime + si; | ||
next_daytime = si; | ||
} else if (next_daytime < si) { | ||
wait_time += si - next_daytime; | ||
next_daytime = si; | ||
} | ||
|
||
next_daytime = (next_daytime + tt / 2) % 1440; | ||
|
||
int fuel_next = min(480, wait_time + now.charge) - tt; | ||
int next_dist = dist[now.code] + wait_time + tt / 2; | ||
|
||
state next_state = state(next, fuel_next, next_daytime); | ||
|
||
if (dist[next_state.code] > next_dist) { | ||
dist[next_state.code] = next_dist; | ||
stim[next_state.code] = next_daytime; | ||
//cout << "Go: " << now.id << " to: " << next << " <=> wait: " << wait_time << " peso " << tt / 2 << " - fuel_next: " << fuel_next << " dt = " << dist[next][next_daytime] << " time: " << next_daytime << "\n"; | ||
q.push(next_state); | ||
} | ||
} | ||
} | ||
} | ||
cout << ans << "\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import java.util.Arrays; | ||
import java.util.Comparator; | ||
import java.util.LinkedList; | ||
import java.util.PriorityQueue; | ||
import java.util.Scanner; | ||
|
||
public class ElectricCarRally { | ||
public static void main(String[] args) { | ||
Scanner in = new Scanner(System.in); | ||
|
||
while (true) { | ||
int n = in.nextInt(), m = in.nextInt(); | ||
if (n == 0 && m == 0) | ||
break; | ||
|
||
LinkedList<Interval>[] a = new LinkedList[n]; | ||
for (int i = 0; i < n; i++) | ||
a[i] = new LinkedList<Interval>(); | ||
|
||
for (int i = 0; i < m; i++) { | ||
int p = in.nextInt(), q = in.nextInt(); | ||
while (true) { | ||
int s = in.nextInt(), t = in.nextInt(), w = in.nextInt(); | ||
if (w <= 240) { | ||
a[p].add(new Interval(q, s, t, w * 2)); | ||
a[q].add(new Interval(p, s, t, w * 2)); | ||
} | ||
if (t == 1439) | ||
break; | ||
} | ||
} | ||
|
||
int best = Integer.MAX_VALUE; | ||
final int[] dist = new int[n * 481], localtime = new int[n * 481]; | ||
Arrays.fill(dist, Integer.MAX_VALUE); | ||
|
||
PriorityQueue<Integer> que = new PriorityQueue<Integer>(n, new Comparator<Integer>() { | ||
public int compare(Integer i, Integer j) { | ||
return dist[i] == dist[j] ? j - i : Integer.compare(dist[i], dist[j]); | ||
} | ||
}); | ||
|
||
que.add(0 * 481 + 480); | ||
dist[que.peek()] = 0; | ||
localtime[que.peek()] = 720; | ||
|
||
while (!que.isEmpty()) { | ||
int p = que.poll(); | ||
if (dist[p] > best) | ||
continue; | ||
|
||
|
||
int fuel = p % 481; | ||
int node = p / 481; | ||
|
||
//System.out.println(node + " " + fuel + " " + dist[p]); | ||
|
||
if (node == n - 1) | ||
best = Math.min(best, dist[p]); | ||
|
||
for (Interval i : a[node]) { | ||
int wait = Math.max(i.distance - fuel, 0); | ||
int time = (localtime[p] + wait) % 1440; | ||
if (time < i.begin) { | ||
wait += i.begin - time; | ||
time = i.begin; | ||
} | ||
if (time > i.end) { | ||
wait += 1440 - time + i.begin; | ||
time = i.begin; | ||
} | ||
|
||
int total = dist[p] + wait + i.distance / 2; | ||
int newfuel = Math.min(wait + fuel, 480) - i.distance; | ||
int newnode = i.to * 481 + newfuel; | ||
if (dist[newnode] > total && total <= best) { | ||
dist[newnode] = total; | ||
|
||
localtime[newnode] = (time + i.distance / 2) % 1440; | ||
//System.out.println("Go " + node + " to: " + newnode / 481 + " dst: " + i.distance + " fuel: " + newfuel + " dist => " + dist[newnode] + " daytime: " + localtime[newnode]); | ||
que.add(newnode); | ||
} | ||
} | ||
} | ||
|
||
System.out.println(best == Integer.MAX_VALUE ? 0 : best); | ||
} | ||
} | ||
|
||
static class Interval { | ||
int begin, end, distance, to; | ||
|
||
Interval(int v, int s, int t, int w) { | ||
to = v; | ||
begin = s; | ||
end = t; | ||
distance = w; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#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; | ||
|
||
typedef long long Int; | ||
typedef unsigned uint; | ||
|
||
string S; | ||
|
||
int main(void) { | ||
while (cin >> S && S != "0") { | ||
vector<int> ans; | ||
for (int i = 1; i < (int) S.size(); i++) { | ||
if (S[i] == '1') { | ||
ans.push_back(i); | ||
for (int j = i; j < (int) S.size(); j += i) { | ||
if (S[j] == '0') { | ||
S[j] = '1'; | ||
} else { | ||
S[j] = '0'; | ||
} | ||
} | ||
} | ||
} | ||
for (int i = 0; i < (int) ans.size(); i++) { | ||
if (i) cout << " "; | ||
cout << ans[i]; | ||
} | ||
cout << "\n"; | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#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; | ||
|
||
typedef long long Int; | ||
typedef unsigned uint; | ||
|
||
const int MAXN = 100005; | ||
const double EPS = 1e-7; | ||
|
||
int N; | ||
double K; | ||
int X[MAXN], Y[MAXN], Z[MAXN]; | ||
|
||
double dist(int i, int j) { | ||
double dx = X[i] - X[j]; | ||
double dy = Y[i] - Y[j]; | ||
double dz = Z[i] - Z[j]; | ||
|
||
return dx * dx + dy * dy + dz * dz; | ||
} | ||
|
||
int main(void) { | ||
while (cin >> N >> K && N != 0) { | ||
int ans = 0; | ||
for (int i = 0; i < N; i++) { | ||
cin >> X[i] >> Y[i] >> Z[i]; | ||
for (int j = 0; j < i; j++) { | ||
if (dist(i, j) + EPS <= K * K) { | ||
ans += 1; | ||
} | ||
} | ||
} | ||
cout << ans << "\n"; | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.