Problem:


Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Runtime Error

Solution code:
import math
N=input()
x=[]
y=[]
M=0
for i in N:
    F=input()
    [v,s]=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in N:
    for j in N:
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/math.factorial(N))

Submission status: Runtime Error

Solution code:
import math
import numpy as np
import itertools
N = int(input())
x = []
y = []
for i in range(N):
    s1,s2 = map(int,input().split())
    x.append(s1)
    y.append(s2)
    
def length(i,j):
    return np.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

LI = [i for i in range(N)]
A = list(itertools.permutations(LI))
ans = 0
for item in A:
#     print(item)
    count = 0
    for i in range(len(item)):
        if i == len(item)-1:
            break
#         print(length(item[count],item[count+1]))
        ans = ans+length(item[count],item[count+1])
        count +=1
print(ans/math.factorial(N))

Submission status: Runtime Error

Solution code:
import numpy as np
import math
N = int(input())
a = list()
for i in range(N):
    a.append(list(map(int, input().split())))
a = np.array(a)    
dis = 0
for i in range(N):
    for j in range(N):
        dis = dis + numpy.linalg.norm(a[i]-a[j])
dis = dis/2
print(dis*2/N)

Submission status: Runtime Error

Solution code:
import math
N=input()
x=[]
y=[]
M=0
for i in N:
    F=input()
    v,s=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in N:
    for j in N:
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/math.factorial(N))

Submission status: Runtime Error

Solution code:
from sys import stdin
#from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return [x for x in mi()]
def si(): return stdin.readline()
def dis(x, y, p, q):
    return sqrt((x-p)**2+(y-q)**2)
a=[]
s=0
n=ii()
fn=1
for i in range(1, n+1):
    fn*=i
fn//=2
for _ in range(n):
    x, y=mi()
    a.append([x, y])
for i in range(n-1):
    for j in range(i+1, n):
        s+=dis(a[i][0], a[i][1], a[j][0], a[j][1])
        #print(s)
print(2*s/n)

Submission status: Runtime Error

Solution code:
from typing import List
import math


class Solution:
    def solve(self, n: int, points: List[List[int]]) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))

Submission status: Runtime Error

Solution code:
import math


class Solution:
    def solve(self, n: int, points: List[List[int]]) -> int:

        s = 0.

        for i in range(n):
            p = points[i]
            for j in range(i+1, n):
                q = points[j]
                s += math.sqrt((p[0]-q[0])**2 + (p[1] - q[1])**2)

        return 2 * s / n


if __name__ == '__main__':

    # standard input
    n = int(input())
    points = []

    for i in range(n):
        x, y = map(int, input().split())
        points.append([x, y])

    # solve
    solution = Solution()
    print(solution.solve(n, points))

Submission status: Runtime Error

Solution code:
n = int(input)
xy = [list(map(int,input().split())) for _ in range(n)]

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += ((xy[i][0] - xy[i][1])**2 + (xy[j][0] - xy[j][1])**2)**0.5
print(ans*2/n)

Submission status: Runtime Error

Solution code:
N = int(input())
Mylist = []
ANSlist = []
for i in range(N):
    a, b = map(int, input())
    Mylist.append([a,b])

for i in range(N):
    for j in range(i,j):
        length = ((abs(Mylist[i][1]-Mylist[j][1]))**2 + (abs(Mylist[i][0]-Mylist[j][0]))**2)**1/2
        ANSlist.append(length)

print(sum(ANSlist)/len(ANSlist))

Submission status: Runtime Error

Solution code:
import math
n = int(input())
x = []
y = []
sum = 0
for i in range(n):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)
for i in range(3):
    for j in  range(3):
        sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
average  = 2*sum/(math.factorial(n))
print(average)

Submission status: Runtime Error

Solution code:
N = int(input())
import math
import itertools

A = [list(map(int, input().split())) for _ in range(N)]

A = list(itertools.permutations(A))

sum = 0

for i in A:
    sum = sum + ((i[0][0]-i[1][0])**2+(i[0][1]-i[1][1]**2))**0.5+((i[1][0]-i[2][0])**2+(i[1][1]-i[2][1]**2))**0.5

print((sum/math.factorial(N)).real)

Submission status: Runtime Error

Solution code:
import math
N=input()
x=[]
y=[]
M=0
for i in N:
    F=input()
    v,s=F.split(' ')
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in N:
    for j in N:
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/math.factorial(N))

Submission status: Runtime Error

Solution code:
n = int(input)
xy = [list(map(int,input().split())) for _ in range(n)]

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    ans += pow(pow(xy[i][0] - xy[i][1],2) + pow(xy[j][0] - xy[j][1],2),0.5)
print(ans*2/n)

Submission status: Runtime Error

Solution code:
import math
import statistics

n = int(input())
xl = []
yl = []

for i in range(n):
    x,y = map(int, input().split())
    xl.append(x)
    yl.append(y)

def d(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2 - (y1-y2)**2)

dd = []
for i in range(n):
    for j in range(i,n):
        dd.append(d(xl[i], yl[i], xl[j], yl[j]))

ans = statistics.mean(dd)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
x = [0] * N
y = [0] * N
for i in range(N):
    x[i], y[i] = map(int, input().split())

import itertools
import numpy as np
import math

np.sqrt(x)

p = list(itertools.permutations(range(N)))

Sum_N = 0

for i in range(len(p)):

    Sum = 0

    for j in range(N - 1):
        Sum += np.sqrt((x[p[i][j]] - x[p[i][j + 1]]) ** 2 + (y[p[i][j]] - y[p[i][j + 1]]) ** 2)

    Sum_N += Sum

print(Sum_N / len(p))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
z=[list(map(input().split())) for i in range(n)]
a=math.factorial(n)
for i in range(n-1):
  for j in range(i,n):
    b=(z[i][0]-z[j][0])**2+(z[i][1]-z[j][1])**2
print(b**0.5/a)

Submission status: Runtime Error

Solution code:
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N = int(input())
    xy = XLMIIS(N)
    

    def distance(x1,y1,x2,y2):
        return ((x1-x2)**2 + (y1-y2) ** 2) ** 0.5

    def f(n):
        ans = n
        if n <= 0:
            return 1
        for i in range(1,n):
            ans *= i
        return ans
    

    sumdis = 0
    for i in range(N):
        for j in range(i+1,N):
            sumdis += distance(*xy[i],*xy[j])
    summ = sumdis  / N * 2
    print(summ)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from itertools import permutations

import numpy as np

N = int(input())

xys = []
for _ in range(N):
    xys.append(list(map(int, input().split())))

combs = np.array(list(permutations(xys, N)))
ret = np.array(
    [np.linalg.norm(combs[:, i] - combs[:, i + 1], axis=1) for i in range(N - 1)]
).sum() / len(combs)

print(f"{ret:.10f}")

Submission status: Runtime Error

Solution code:
n = int(input())
pl = list()
for i in range(n):
    pl.append(list(map(int, input().split(()))))

import math
lsum = 0
for i in range(n):
    for j in range(n): 
        if i != j:
            a, b = pl[i]
            c, d = pl[j]
            lsum += math.sqrt((a-c) ** 2 + (b-d) ** 2)
print(lsum / 4 * math.factorial(n) * 2 / 3)

Submission status: Runtime Error

Solution code:
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
D = [[0]*N for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        D[i][j] = D[j][i] = ( (L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2 )**0.5

M = [-1]*N
pathlist = []
def makepath(k, prev):
    if k==8: pathlist.append(M[:])
    for i in range(N):
        if M[i]>=0: continue
        M[i] = k
        makepath(k+1, i)
        M[i] = -1

makepath(0, -1)

s = 0
for p in pathlist:
    for i in range(N-1):
        s += D[p[i]][p[i+1]]
        
print(s/len(pathlist))

Submission status: Runtime Error

Solution code:
n = int(input())

ls = [map(int(input().split())) for _ in range(n)]

sum = 0
for i in range(n-1):
  for j in range(1,n):
    sum += ((ls[i][0]-ls[j][0])**2+(ls[i][1]-ls[j][1])**2)**0.5
    
print(sum*2/n)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
l1 = []
l = []
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    l.append(i)
    l1.append((x,y))
per = permutations(l)
for elm in per:
    for i in range(1,len(elm)):
        x=(((l1[elm[i]][0]-l1[elm[i-1]][0])**2)+((l1[elm[i]][1]-l1[elm[i-1]][1])**2))
        ans+=math.sqrt(x)
ans = ans/(math.factorial(n))
print(ans)

Submission status: Runtime Error

Solution code:
import itertools
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
tmp = list(itertools.permutations(list(range(N)),N))
length = []
for i in range(len(tmp)):
    tmplen = ((xy[tmp[i][0]][0]-xy[tmp[i][1]][0])**2+(xy[tmp[i][0]][1]-xy[tmp[i][1]][1])**2)**(1/2)
    tmplen += ((xy[tmp[i][1]][0]-xy[tmp[i][2]][0])**2+(xy[tmp[i][1]][1]-xy[tmp[i][2]][1])**2)**(1/2)
    length.append(tmplen)
print(sum(length)/len(length))
print(xy)

Submission status: Runtime Error

Solution code:
import math
def length(X,Y,c):
    sum_=0
    for i in range(len(c)-1):
        sum_+=math.sqrt((X[c[i]]-X[c[i+1]])**2 + (Y[c[i]]-Y[c[i+1]])**2)
    #print(sum_)
    return sum_
N=int(input())
X=[0]*N
Y=[0]*N
for i in range(N):
    X[i], Y[i] = map(int,input().split())
C = list(itertools.permutations(range(0,N)))
sum_=0
for c in C:
    sum_+=length(X,Y,c)
print(sum_/len(C))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
# coding: utf-8
# Last Modified: 16/Nov/19 05:40:04 PM


import sys


def main():
    from math import factorial, sqrt
    from itertools import permutations

    n = int(input())
    arr = [get_array() for _ in range(n)]

    x = range(n)
    p = list(permutations(x))

    def dis(x1, y1, x2, y2):
        return sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)

    distance = 0
    for j in p:
        for i in range(1, len(j)):
            distance += dis(*arr[j[i]], *arr[j[i - 1]])
    print(distance / factorial(n))


get_array = lambda: list(map(int, sys.stdin.readline().split()))


get_ints = lambda: map(int, sys.stdin.readline().split())


input = lambda: sys.stdin.readline().strip()


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from itertools import permutations

def factorial(n):
  if n < 2:
    return 1
  return n * factorial(n - 1)


def distance(a, b):
  dx = a[0] - b[0]
  dy = a[1] - b[1]
  return sqrt(dx * dx + dy * dy)
  

def calc_len(points, perm):
  res = 0
  for i in range(1, len(perm)):
    a = points[perm[i]]
    b = points[perm[i - 1]]
    res += distance(a, b)
  return res


n = int(input())
points = []
for _ in range(n):
  x, y = map(int, input().split())
  points.append((x, y))
  
total_len = 0
for perm in permutations(list(range(n))):
  total_len += calc_len(points, perm)
print(total_left / factorial(n))

Submission status: Runtime Error

Solution code:
/// awoooooo

# include <bits/stdc++.h>
# define sz(x) (int)((x).size())

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair < int, int > pii;

const int N = (int)2e5 + 5;
const int inf = (int)1e9 + 7;


int n;
int x[N], y[N], p[N];

int main(){
  cin >> n;

  for(int i = 1; i <= n; ++i){
    cin >> x[i] >> y[i];
    p[i] = i;
  }
  ld ans = 0;
  int cnt = 0;
  do{
    for(int i = 1; i < n; ++i){
      ans += sqrtl((x[p[i]] - x[p[i + 1]]) * (x[p[i]] - x[p[i + 1]]) + (y[p[i]] - y[p[i + 1]]) * (y[p[i]] - y[p[i + 1]]));
    }
    ++cnt;
  }while(next_permutation(p + 1, p + 1 + n));
  cout << fixed << setprecision(11) << ans / cnt;

  return 0;
}

Submission status: Runtime Error

Solution code:
from itertools import permutations

N = int(input())

def length(x, y, u, v):
    return ((x - u)**2 + (y - v)**2)**0.5

XY = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0

for x in permutations(range(N)):
    for fr, to in zip(x, x[1:]):
        ans += length(*XY[fr], *XY[to])

for i in range(1, N + 1):
    ans /= i

print(ans)