import java.util.*; public class Voyager { public static void main(String[] args){ String input = "2\n"+ "2 3\n" + "1 1\n"+ "8 2\n"+ "2 2\n"+ "4 4\n"+ "7 3\n"+ "2 3\n"+ "1 1\n"+ "8 2\n"+ "2 2\n"+ "4 4\n"+ "7 4\n"; Scanner s = new Scanner(input); int cases = s.nextInt(); for(int i=0;i tNodes = new HashMap(); // starting point might be in the intersection of two towers List startingTowers = findStartingPoint(src, towers, radius); for(int i=0;i path = new ArrayList(); // this is extra to tell you which towers we traveled static List tPath = new ArrayList(); static double distance = Double.MAX_VALUE; static double minDist = distance; public static void computeMinimum(){ double total = 0; for(int i=0;i total) minDist = total; } public static void voyage(Coordinate src, Coordinate dest, int fromTower, Map map ){ voyage(src,dest, map.get(fromTower),map); } public static void voyage(Coordinate src, Coordinate dest, Node fromNode, Map map ){ //did I reach my destination? if( fromNode.hasPoint(dest)){ path.add(src); path.add(dest); computeMinimum(); //clean up if(!tPath.isEmpty()){ tPath.remove(tPath.size()-1); path.remove(path.size()-1); } return; } // keep track of the coordinates we have already visited path.add( src); //keep track of the towers we have already visited tPath.add( fromNode.tower); //get the list of towers we can travel to List lstOfTowers = fromNode.getTowers(); for(int i=0;i lstOfPoints = fromNode.getPoints(curTower); for(int j=0;j findStartingPoint(Coordinate src, Coordinate[] towers, int radius){ List lst = new ArrayList(); for(int i=0;i 2*r; } } class Coordinate{ double x; double y; Coordinate(double x, double y){ this.x = x; this.y = y; } public String toString(){ return "(" + x + "," + y + ")"; } public boolean equals(Object o){ if(o instanceof Coordinate){ Coordinate c = (Coordinate) o; return c.x ==x && c.y == y; }else return false; } public double distance(Coordinate c){ double dx = c.x - this.x; double dy = c.y - this.y; return Math.sqrt( dx * dx + dy * dy); } public static boolean isInCircle(Coordinate xy, Coordinate c, double r){ return xy.distance(c) <= r; } } /* * class to represent each tower information */ class Node{ Map> map = new HashMap>(); int tower ; Coordinate center; double radius; public Node(int tower, Coordinate center, double radius){ this.tower = tower; this.center = center; this.radius = radius; } public List getPoints(int _tower){ return map.get(_tower); } public List getTowers(){ Iterator iter = map.keySet().iterator(); List list = new ArrayList(); while(iter.hasNext()) list.add( iter.next()); return list; } public void add(Coordinate c, int _tower){ List list = map.get(_tower); if(list == null){ list = new ArrayList(); } if(list.indexOf(c) == -1){ list.add( c); } map.put(_tower,list); } //public List getList(){ return lst;} public String toString(){ return " tower " + tower + " lst:" + map; } public boolean equals(Object o){ Node n = (Node) o; return n.tower == tower; } public int hashCode(){ return tower; } public boolean hasPoint(Coordinate p){ return Coordinate.isInCircle(p, center, radius); } }