Go to diff to previous submission
import java.io.BufferedReader; import java.io.InputStreamReader; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.HashMap; import java.util.LinkedList; import java.util.TreeMap; class Edge implements Comparable<Edge> { public int dx, dy, dz; @Override public int compareTo(Edge arg0) { return t.compareTo(arg0.t); } public Edge(double t, int dx, int dy, int dz) { this.t = t; this.dx = dx; this.dy = dy; this.dz = dz; } public double angleTo(Edge e) { (dx * e.dx + dy * e.dy + dz * e.dz)/ ) ); } } class Node { public int x, y, z; public LinkedList<Node> nbh; public boolean end, visited; @Override public int hashCode() { return x ^ y ^ z; }; @Override { if (arg0 instanceof Node) { Node a = (Node)arg0; return (x == a.x) && (y == a.y) && (z == a.z); } return false; } public Node(int x, int y, int z, boolean end) { this.x = x; this.y = y; this.z = z; this.end = end; visited = false; nbh = new LinkedList<Node>(); } public double distanceTo(Node node) { int dx = node.x - x; int dy = node.y - y; int dz = node.z - z; } public Edge edgeTo(Node node, double t) { int dx = node.x - x; int dy = node.y - y; int dz = node.z - z; return new Edge(t, -dx, -dy, -dz); } } public class Cockchaf { public static double time(double dist, double speed) { return dist / speed; } /** * @param args */ String s; HashMap<Node, Node> nMap = new HashMap<Node, Node>(); int n, ssp; double dist, t, angle, asp; Edge e, e2; Node a, b, start; TreeMap<Edge, Node> pq = new TreeMap<Edge, Node>(); while (true) { s = br.readLine(); if (s == null) break; ss = s.split(" "); s = br.readLine(); ss = s.split(" "); start = a; nMap.put(a, a); nMap.put(b, b); for (int i = 0; i < n; i++) { s = br.readLine(); ss = s.split(" "); if (nMap.containsKey(a)) a = nMap.get(a); else nMap.put(a, a); if (nMap.containsKey(b)) b = nMap.get(b); else nMap.put(b, b); a.nbh.addLast(b); b.nbh.addLast(a); } a = start; a.visited = true; for (Node node : a.nbh) { dist = a.distanceTo(node); pq.put(a.edgeTo(node, time(dist, ssp)), node); } while (!pq.isEmpty()) { e = pq.firstKey(); a = pq.remove(e); t = e.t; if (a.visited) continue; a.visited = true; if (a.end) { } for (Node node : a.nbh) { e2 = a.edgeTo(node, t); dist = a.distanceTo(node); angle = e.angleTo(e2); e2.t += time(angle, asp) + time(dist, ssp); pq.put(e2, node); } } } } }
--- c4.s1022.cteam112.cockchaf.java.0.Cockchaf.java +++ c4.s1165.cteam112.cockchaf.java.0.Cockchaf.java @@ -81,5 +81,5 @@ int dy = node.y - y; int dz = node.z - z; - return new Edge(t, dx, dy, dz); + return new Edge(t, -dx, -dy, -dz); } } @@ -166,5 +166,5 @@ if (a.end) { - DecimalFormat nf = new DecimalFormat("#.####"); + DecimalFormat nf = new DecimalFormat("0.0000"); System.out.println(nf.format(e.t).replace(',', '.')); }