Source code for submission s1086

Cockchaf.java

  1.  
  2. import java.util.ArrayList;
  3. import java.util.HashMap;
  4. import java.util.HashSet;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.PriorityQueue;
  8. import java.util.Queue;
  9. import java.util.Scanner;
  10. import java.util.Set;
  11.  
  12.  
  13.  
  14. /**
  15.  *
  16.  * @author cteam018
  17.  */
  18. public class Cockchaf {
  19. static class Step implements Comparable<Step>{
  20. Point p;
  21. double dx,dy,dz;
  22. double time;
  23.  
  24. Step (Point p_, double dx_, double dy_, double dz_,double time_){
  25. p = p_;
  26. dx = dx_;
  27. dy = dy_;
  28. dz = dz_;
  29. time = time_;
  30. }
  31.  
  32. public int compareTo(Step s) {
  33. double e = 0.0000001;
  34. if (s.time-time > e) return -1;
  35. if (time-s.time > e) return 1;
  36. return 0;
  37. }
  38. }
  39.  
  40. static class Point {
  41.  
  42. @Override
  43. public boolean equals(Object obj) {
  44. if (obj == null) {
  45. return false;
  46. }
  47. if (getClass() != obj.getClass()) {
  48. return false;
  49. }
  50. final Point other = (Point) obj;
  51. if (this.x != other.x) {
  52. return false;
  53. }
  54. if (this.y != other.y) {
  55. return false;
  56. }
  57. if (this.z != other.z) {
  58. return false;
  59. }
  60. return true;
  61. }
  62.  
  63. @Override
  64. public int hashCode() {
  65. int hash = 3;
  66. hash = 47 * hash + this.x;
  67. hash = 47 * hash + this.y;
  68. hash = 47 * hash + this.z;
  69. return hash;
  70. }
  71.  
  72. int x,y,z;
  73. List<Point> e = new ArrayList<Point>();
  74.  
  75. Point(int x,int y, int z){
  76. this.x = x;
  77. this.y = y;
  78. this.z = z;
  79.  
  80. }
  81.  
  82. };
  83.  
  84. static double length(double x1, double x2, double x3, double y1, double y2, double y3){
  85. return Math.sqrt((x1-y1)*(x1-y1)+(x2-y2)*(x2-y2)+(x3-y3)*(x3-y3));
  86. }
  87.  
  88. static double degToTurn(double u1,double u2,double u3,double v1,double v2,double v3){
  89. double d;
  90. d = Math.acos((u1*v1+u2*v2+u3*v3)/(length(0,0,0,u1,u2,u3)*length(0,0,0,v1,v2,v3)));
  91. return d*180/Math.PI;
  92. }
  93.  
  94. public static void main(String[] args) {
  95. Scanner sc = new Scanner(System.in);
  96. while (sc.hasNextInt()){
  97. int N = sc.nextInt();
  98. int S = sc.nextInt();
  99. int T = sc.nextInt();
  100. Point start = new Point(sc.nextInt(),sc.nextInt(),sc.nextInt());
  101. Point end = new Point(sc.nextInt(),sc.nextInt(),sc.nextInt());
  102. List<Point> points = new ArrayList<Point>();
  103. points.add(start);
  104. points.add(end);
  105. for (int i=0; i<N; i++){
  106. Point p1 = new Point(sc.nextInt(),sc.nextInt(),sc.nextInt());
  107. Point p2 = new Point(sc.nextInt(),sc.nextInt(),sc.nextInt());
  108. Point p1R = null, p2R = null;
  109. for (int j=0; j<points.size(); j++){
  110. if (points.get(j).equals(p1)){
  111. p1R = points.get(j);
  112. }
  113. if (points.get(j).equals(p2)){
  114. p2R = points.get(j);
  115. }
  116. if (p1R != null && p2R != null) break;
  117. }
  118. if (p1R == null){
  119. p1R = p1;
  120. points.add(p1R);
  121. }
  122. if (p2R == null){
  123. p2R = p2;
  124. points.add(p2R);
  125. }
  126.  
  127. p1R.e.add(p2R);
  128. p2R.e.add(p1R);
  129. }
  130.  
  131. Queue<Step> q = new PriorityQueue<Step>();
  132. //init
  133. for (int i=0; i<start.e.size(); i++){
  134. double d = length(start.x, start.y, start.z, start.e.get(i).x, start.e.get(i).y, start.e.get(i).z);
  135. double dx = start.e.get(i).x - start.x;
  136. double dy = start.e.get(i).y - start.y;
  137. double dz = start.e.get(i).z - start.z;
  138. q.add(new Step(start.e.get(i), dx, dy, dz, d/S));
  139. System.err.println(d/S);
  140. }
  141.  
  142. while (true) {
  143. Step c = q.poll();
  144. if (c.p.equals(end)){
  145. System.out.printf("%.4f\n", c.time);
  146. break;
  147. }
  148. for (int i=0; i<c.p.e.size(); i++){
  149. double d = length(c.p.x,c.p.y,c.p.z,c.p.e.get(i).x,c.p.e.get(i).y, c.p.e.get(i).z);
  150. double dx = c.p.e.get(i).x - c.p.x;
  151. double dy = c.p.e.get(i).y - c.p.y;
  152. double dz = c.p.e.get(i).z - c.p.z;
  153. double t = degToTurn(c.dx, c.dy, c.dz, dx, dy, dz);
  154. q.add(new Step(c.p.e.get(i), dx, dy, dz, c.time + d/S + t/T));
  155. }
  156. }
  157.  
  158. }
  159. }
  160.  
  161.  
  162. }
  163.