Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Array.prototype.remove = function() {
- var what, a = arguments, L = a.length, ax;
- while (L && this.length) {
- what = a[--L];
- while ((ax = this.indexOf(what)) !== -1) {
- this.splice(ax, 1);
- }
- }
- return this;
- };
- let map =[]
- const N = parseInt(readline());
- let TotalDistance = 0
- for (let i = 0; i < N; i++) {
- var inputs = readline().split(' ');
- const X = parseInt(inputs[0]);
- const Y = parseInt(inputs[1]);
- map.push([X,Y])
- }
- let currentLoc = map[0]
- for(let i = 0; i< map.length; i){
- print(currentLoc)
- print(map)
- print(map.indexOf(currentLoc))
- map.remove(currentLoc)
- let CurrentDistance = 10000
- let chosenLoc = [0,0]
- for(let j = map.length-1; j>=0;j--){
- let newDist = Math.sqrt(Math.pow(map[j][0]-currentLoc[0],2)+Math.pow(map[j][1]-currentLoc[1],2))
- if(CurrentDistance>newDist){
- CurrentDistance=newDist
- chosenLoc = [map[j][0],map[j][1]]
- }
- }
- TotalDistance += CurrentDistance
- currentLoc[0] = chosenLoc[0]
- currentLoc[1] = chosenLoc[1]
- }
- print(TotalDistance)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement