Advertisement
Guest User

Untitled

a guest
Mar 18th, 2021
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. Array.prototype.remove = function() {
  2. var what, a = arguments, L = a.length, ax;
  3. while (L && this.length) {
  4. what = a[--L];
  5. while ((ax = this.indexOf(what)) !== -1) {
  6. this.splice(ax, 1);
  7. }
  8. }
  9. return this;
  10. };
  11.  
  12. let map =[]
  13. const N = parseInt(readline());
  14. let TotalDistance = 0
  15. for (let i = 0; i < N; i++) {
  16. var inputs = readline().split(' ');
  17. const X = parseInt(inputs[0]);
  18. const Y = parseInt(inputs[1]);
  19. map.push([X,Y])
  20. }
  21.  
  22. let currentLoc = map[0]
  23. for(let i = 0; i< map.length; i){
  24. print(currentLoc)
  25. print(map)
  26. print(map.indexOf(currentLoc))
  27. map.remove(currentLoc)
  28.  
  29. let CurrentDistance = 10000
  30. let chosenLoc = [0,0]
  31. for(let j = map.length-1; j>=0;j--){
  32. let newDist = Math.sqrt(Math.pow(map[j][0]-currentLoc[0],2)+Math.pow(map[j][1]-currentLoc[1],2))
  33.  
  34.  
  35. if(CurrentDistance>newDist){
  36. CurrentDistance=newDist
  37. chosenLoc = [map[j][0],map[j][1]]
  38.  
  39.  
  40. }
  41. }
  42. TotalDistance += CurrentDistance
  43.  
  44. currentLoc[0] = chosenLoc[0]
  45. currentLoc[1] = chosenLoc[1]
  46.  
  47. }
  48.  
  49. print(TotalDistance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement