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: Accepted

Solution code:
import math
import itertools

N = int(input())

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


# 順列の生成
p = itertools.permutations(range(N))

# 総数
totalCount = math.factorial(N)

prevX = 0
prevY = 0

totalKyori = 0

for nr in p:
    for i, nt in enumerate(nr):
        if i == 0:
            prevX = towns[nt][0]
            prevY = towns[nt][1]
        else:
            # 前の町と今の町の距離を計算
            kyori = math.sqrt( (prevX - towns[nt][0])**2 + (prevY - towns[nt][1])**2 )
            totalKyori += kyori


print(totalKyori / totalCount)

Submission status: Accepted

Solution code:
import math
N=int(input())
x=[]
for _ in range(N):
  a,b=map(int,input().split())
  x.append([a,b])
l=0
for i in range(0,N):
  for j in range(i+1,N):
    l+=math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)
print(2*l/N)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

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

ans = []
for paths in permutations(range(n)):
    x = xy[paths[0]][0]
    y = xy[paths[0]][1]
    dist = 0
    for i in paths[1:]:
        x2 = xy[i][0]
        y2 = xy[i][1]
        dist += sqrt((x2 - x) ** 2 + (y2 - y) ** 2)
        x, y = x2, y2
    ans.append(dist)

print(sum(ans) / len(ans))

Submission status: Accepted

Solution code:
import math
n=int(input())
x=[]
for _ in range(n):
    a,b=map(int, input().split())
    x.append([a,b])

l=0
for i in range(n):
    for j in range(n):
        l+=math.sqrt((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)
print(l/n)

Submission status: Accepted

Solution code:
# ABC145C - Average Length
from itertools import permutations


def calc(seq: "Array[int]") -> float:
    ret = 0
    for i, j in zip(seq, seq[1:]):
        xi, yi = XY[i]
        xj, yj = XY[j]
        ret += ((xi - xj) ** 2 + (yi - yj) ** 2) ** 0.5
    return ret


def fact(x: int) -> int:
    ret = 1
    for i in range(1, x + 1):
        ret *= i
    return ret


def main():
    global XY
    N, *XY = map(int, open(0).read().split())
    XY = list(zip(*[iter(XY)] * 2))
    ans = sum(calc(perm) for perm in permutations(range(N), N)) / fact(N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    sum_v = 0
    for i in range(n-1):
        for j in range(i+1, n):
            if i != j:
                sum_v += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations as combi
from math import sqrt
n=int(input())
x=[]
y=[]
sum=0
for i in range(n):
    xx,yy=map(int,input().split())
    x.append(xx)
    y.append(yy)
for a,b in combi(range(n),2):
    dx=x[a]-x[b]
    dy=y[a]-y[b]
    d=sqrt(dx**2+dy**2)
    sum+=d
ans=sum*2/n
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    checked = [[None for _ in range(n)] for _ in range(n)]
    sum_v = 0
    p = 1
    for i in range(n):
        p *= i + 1
        for j in range(n):
            if i == j or checked[i][j] is not None:
                continue
            checked[i][j] = 1
            checked[j][i] = 1
            sum_v += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    dis = [[None for _ in range(n)] for _ in range(n)]
    sum_v = 0
    p = 1
    for i in range(n):
        p *= i + 1
        for j in range(n):
            if i == j or dis[i][j] is not None:
                continue
            d = math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
            dis[i][j] = d
            dis[j][i] = d
            sum_v += d
    print(sum_v * 2 / n)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
lis = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(N):
        if i != j:
           ans += ((lis[i][0]-lis[j][0])**2+(lis[i][1]-lis[j][1])**2)**0.5
print(ans/N)

Submission status: Accepted

Solution code:
def p_c():
    from itertools import permutations
    from math import sqrt
    n = int(input())
    xy = [tuple(map(int, input().split())) for _ in range(n)]
    ans = []
    for per in permutations(list(range(n))):
        x, y = xy[per[0]]
        dist = 0
        for i in per[1:]:
            x2, y2 = xy[i]
            dist += sqrt((x2 - x) ** 2 + (y2 - y) ** 2)
            x, y = x2, y2
        ans.append(dist)
    print(sum(ans) / len(ans))
    
p_c()

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    X = [0]*N
    Y = [0]*N
    for i in range(N):
        X[i], Y[i] = map(int, input().split())
    
    r = [[0]*N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            r[i][j] = math.sqrt((X[i] - X[j])**2 + (Y[i] - Y[j])**2)

    ans = 0
    for route in itertools.permutations([i for i in range(N)]):
        for i in range(N-1):
            ans += r[route[i]][route[i+1]]
    ans /= math.factorial(N)

    print(ans)
        

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools as it
n = int(input())
towns = []
for i in range(n):
    towns.append(list(map(int,input().split())))
ans = 0
count = 0
for ts in it.permutations(towns):
    for i in range(len(ts)-1):
        ans += ((ts[i][0]-ts[i+1][0])**2+(ts[i][1]-ts[i+1][1])**2)**0.5
    count += 1
print(ans/count)

Submission status: Accepted

Solution code:
import itertools
N = int(input())
num = [i for i in range(N)]
lst = [list(map(int,input().split())) for i in range(N)]
routes = list(itertools.permutations(num))
sum_route = 0
for route in routes:
  for i in range(len(route) - 1):
    x1 = lst[route[i]][0]
    y1 = lst[route[i]][1]
    x2 = lst[route[i+1]][0]
    y2 = lst[route[i+1]][1]
    sum_route += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
print(sum_route / len(routes))

Submission status: Accepted

Solution code:
import itertools
import math

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

path = 0
for c1, c2 in itertools.product(L, L):
    path += math.sqrt((c1[0]-c2[0])**2 + (c1[1]-c2[1])**2)

print(path/N)

Submission status: Accepted

Solution code:
fact = [1]
for i in range(1,14):
    fact.append(fact[-1]*i)
n = int(input())
def dist(a,b):
    return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
a = []
for i in range(n):
    x,y = map(int,input().split())
    a.append([x,y])
ans = 0;
for i in a:
    for j in a:
        ans+=(dist(i,j)*fact[n-1])
print(ans/fact[n])

Submission status: Accepted

Solution code:
import itertools
import math

N=int(input())

town=[]
result=0
count=0

for i in range(N):
    town.append([int(x) for x in input().split()])

tag=list(itertools.permutations(town))

for val in tag:
    #print(val)
    for i in range(0,len(val)-1):
        #print(val[i][0],val[i+1][0])
        #print(val[i][1],val[i+1][1])
        buf=pow(val[i][0]-val[i+1][0],2)
        tmp=pow(val[i][1]-val[i+1][1],2)
        #print("buf:",buf)
        #print("tmp:",tmp)
        result+=(math.sqrt(buf+tmp))

print(result/math.factorial(N))

Submission status: Accepted

Solution code:
from itertools import permutations

n = int(input())
XY = [tuple(map(int, input().split())) for i in range(n)]

num = 0
path_length = 0
for p in permutations(XY):
    num += 1
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1-x2)**2 +(y1-y2)**2)**0.5

print(path_length/num)

Submission status: Accepted

Solution code:
#%%
from itertools import permutations
N = int(input())

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

perm = list(permutations(towns))

def calc_l2(p_next, p):
    return ((p_next[0] - p[0])**2 + (p_next[1] - p[1])**2) ** 0.5

l2_norm = 0
for p in perm:
    for i in range(len(p) - 1):
        l2_norm += calc_l2(p[i+1], p[i])

print(l2_norm/len(perm))

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]

path = itertools.permutations([i for i in range(n)])

ans = []
for town in list(path):
    total = 0
    for i in range(n-1):
        total += math.sqrt((p[town[i]][0]-p[town[i+1]][0])**2 + (p[town[i]][1]-p[town[i+1]][1])**2)
    ans.append(total)

print(sum(ans)/math.factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
town = [list(map(int, input().split())) for _ in range(N)]
path = []
for p in itertools.permutations(town):
    path.append(sum([math.sqrt((p[i+1][0]-p[i][0])**2 + (p[i+1][1]-p[i][1])**2) for i in range(len(p)-1)]))

print(sum(path)/len(path))

Submission status: Accepted

Solution code:
import numpy as np
import itertools
import math
N = int(input())
place = np.zeros((N, 2))
for i in range(N):
  x, y = map(int, input().split())
  place[i,:] = [x,y]
length = np.zeros((N, N))
for i in range(N):
  a = np.array(place[i,:])
  for j in range(i,N):
    b = np.array(place[j,:])
    length[j,i] = length[i,j] = np.linalg.norm(b-a)

s = np.zeros(math.factorial(N))
for i,order in enumerate(list(itertools.permutations(list(range(N))))):
  for j in range(N-1):
    s[i] += length[order[j], order[j+1]]
    
print(np.mean(s))

Submission status: Accepted

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

dis=0
a=0
for x in itertools.permutations(L):
    for i in range(n-1):
        dis+=math.sqrt((x[i][0]-x[i+1][0])**2+(x[i][1]-x[i+1][1])**2)
    a+=1

print(dis/a)

Submission status: Accepted

Solution code:
from math import factorial
from itertools import permutations


def dist(t1, t2):
    return ((t1[0] - t2[0])**2+(t1[1] - t2[1])**2)**0.5


N = int(input())
l_cities = [None] * N

for i in range(N):
    l_cities[i] = tuple(map(int, input().split()))

perm_l = permutations(list(range(N)))

summ = 0

for l_p in perm_l:
    for i in range(1, N):
        summ += dist(l_cities[l_p[i-1]], l_cities[l_p[i]])
    
avg_mean = summ / factorial(N)
print(avg_mean)

Submission status: Accepted

Solution code:
from itertools import permutations
import math

def distance(p1, p2):
    return math.sqrt(((p1[0] - p2[0])**2) +  ((p1[1] - p2[1])**2))


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



paths = list(permutations(paths))
avg = 0
for path in paths:
    for i in range(len(path) - 1):
        avg += distance(path[i], path[i+1])

print(avg / len(paths))

Submission status: Accepted

Solution code:
import math

N = int(input())

towns = []
townx = []
towny = []

for i in range(N):
    x, y = map(int, input().split(' '))
    townx.append(x)
    towny.append(y)

distances = [[math.sqrt((townx[i] - townx[j]) ** 2 + (towny[i] - towny[j]) ** 2) for j in range(N)] for i in range(N)]

fact = math.factorial(N)
res = sum([sum(distance) for distance in distances])

print(res/N)

Submission status: Accepted

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 math
dim = 0
count = 0
for n in itertools.permutations(range(N)):
    count += 1
    for num in range(1,N):
        x_dim = pow((x[n[num-1]]-x[n[num]]), 2)
        y_dim = pow((y[n[num-1]]-y[n[num]]), 2)
        dim += math.sqrt(x_dim + y_dim)

print(dim/count)

Submission status: Accepted

Solution code:
import math
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]
sum = 0
for i in range(n-1):
    for j in range(i+1, n):
        sum += math.sqrt((l[j][0] - l[i][0]) ** 2 +
                         (l[j][1] - l[i][1]) ** 2)
print(sum * 2 / n)

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
a = []
x = []
y = []
count = 0

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

for i in range(N):
    a.append(list(map(int,input().split())))    
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        count += np.sqrt((a[i][0] - a[j][0])**2 + (a[i][1] - a[j][1])**2)
b = factorial(N)
print(count/N)

Submission status: Accepted

Solution code:
n = int(input())
A = []
for _ in range(n):
    x, y = map(int, input().split())
    A.append([x, y])
import itertools, math
tmp = 0
l = len(list(itertools.permutations(A, n)))
for x in itertools.permutations(A, n):
    for i in range(1, n):
        xi, xj, yi, yj = x[i-1][0], x[i][0], x[i-1][1], x[i][1]
        tmp += math.sqrt(((xi - xj) ** 2) + ((yi - yj) ** 2))
print(tmp / l)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
AllList = list(range(0, N))


Coord = [[] for _ in range(N)]
Distance = [[0 for _ in range(N)] for _ in range(N)]
for i in range(0, N):
    x, y = map(int, input().split())
    Coord[i] = [x, y]


count = 0
for i in range(0, N):
    for q in range(0, N):
        if i == q:
            continue
        Distance[i][q] = np.sqrt((Coord[i][0] - Coord[q][0]) ** 2 + (Coord[i][1] - Coord[q][1]) ** 2)
        count += Distance[i][q]
count = count / N
print(count)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

N = int(input())
l = []
for i in range(N):
	l.append(list(map(int,input().split())))
    
r = 0
for i,j in itertools.product(l,l):
	r += np.sqrt((i[0]-j[0])**2 + (i[1]-j[1])**2)

print(r/N)

Submission status: Accepted

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

t = 0
for i in range(n - 1):
    for j in range(i, n):
        t += ((lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2) ** 0.5

print(2 * t / n)

Submission status: Accepted

Solution code:
N=int(input())

A=[input().split() for i in range(N)]
x=0
y=1
L=0
num=0
import itertools
import math
citylist=[0]*N
#０からN-1までのN要素のリスト生成
for j in range(N):
  citylist[j]=j

Plist=list(itertools.permutations(citylist))

for l in range(math.factorial(N)):
  L=0
  for k in range(N-1):
    L+=((int(A[Plist[l][k]][x])-int(A[Plist[l][k+1]][x]))**2+(int(A[Plist[l][k]][y])-int(A[Plist[l][k+1]][y]))**2)**(1/2)
  num+=L
  
print(num/math.factorial(N))

Submission status: Accepted

Solution code:
def n_n(n):
  c = 1
  for i in range(1,n+1):
    c = c * i
  return c
import itertools as itr
N = int(input())
n = n_n(N)

rr=[]
xy = [[0,0]] * (N)
for i in range(N):
  xy[i] = list(map(int,input().split()))
  
all = list(itr.permutations(xy))
for line in all:
  r = [0] * (N+1)
  x = [0]*(N+1)
  y = [0]*(N+1)
  for i in range(N-1):
    x[i+1] = line[i+1][0] - line[i][0]
    y[i+1] = line[i+1][1] - line[i][1]
    r[i+1] = (x[i+1]**2 + y[i+1]**2)**(1/2)
  rr.append(sum(i for i in r))
print(sum(i for i in rr)/n)

Submission status: Accepted

Solution code:
import math

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

dis = [[0]*n for _ in range(n)]

for i in range(n):
    for j in range(n):
        dis[i][j] = math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)

ans = 0

for i in range(n):
    for j in range(i+1,n):
        ans += dis[i][j] * math.factorial(n-1) * 2

print(ans/math.factorial(n))

Submission status: Accepted

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

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

total = 0
for i in range(N):
    for k in range(N):
        total += kyori(x[i], y[i], x[k], y[k])

total = total / N
print(total)

Submission status: Accepted

Solution code:
import math
N = int(input())
list = list()
sum = 0
for i in range(N):
    x, y = map(int, input().split())
    list.append((x, y))
for i in range(N):
    for j in range(i+1, N):
        sum += math.sqrt((list[i][0]-list[j][0])**2 + (list[i][1]-list[j][1])**2)
print(sum*2/N)

Submission status: Accepted

Solution code:
import math
import itertools

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

li=list(range(N))
co=[]
sum=0

for i in itertools.permutations(li,N):
    co.append(list(i))

for i in range(len(co)):
    for j in range(N-1):
        sum+=((xy[co[i][j]][0]-xy[co[i][j+1]][0])**2+(xy[co[i][j]][1]-xy[co[i][j+1]][1])**2)**(1/2)
print(sum/len(co))

Submission status: Accepted

Solution code:
import itertools
import math

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


total = 0
for perm in itertools.permutations(points):
    for i in range(n - 1):
        p1 = perm[i]
        p2 = perm[i + 1]
        dist = math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
        total += dist

avg = total / math.factorial(n)


print(avg)

Submission status: Accepted

Solution code:
import math


def main():
    N = int(input())
    xy_list = [list(map(int, input().split())) for i in range(N)]

    sum = 0

    for i, xy1 in enumerate(xy_list):
        for j, xy2 in enumerate(xy_list):
            if i == j:
                continue

            x1 = xy1[0]
            x2 = xy2[0]
            y1 = xy1[1]
            y2 = xy2[1]

            sum += math.sqrt((x1-x2)**2 + (y1-y2)**2)

    print(sum/N)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N=int(input())
l=list()
a=0
for i in range(N):
    l.append(list(map(int,input().split())))
    for _ in l:
        a+=((_[0]-l[-1][0])**2+(_[1]-l[-1][1])**2)**(1/2)
print(2*a/N)

Submission status: Accepted

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

ans = 0
for i in xy:
    for j in xy:
        ans += ((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) ** 0.5

print(ans/n)

Submission status: Accepted

Solution code:
n = int(input())
X = []
Y = []
for _ in range(n):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)
    
dist = 0
import math 
for j in range(n):
    for k in range(n):
        dist += math.sqrt((X[j]-X[k])**2+(Y[j]-Y[k])**2)
        
print(dist/n)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt, pow

n = int(input())
x = []
y = []
for i in range(n):
    m = input().split()
    x.append(int(m[0]))
    y.append(int(m[1]))

l = []
for i in range(n):
    l.append(i)

p = list(permutations(l))
ave = 0
cnt = 0
for i in p:
    j = 0
    while (j < n - 1):
        ave += sqrt(pow(x[i[j]] - x[i[j + 1]], 2) + pow(y[i[j]] - y[i[j + 1]], 2))
        j += 1
    cnt += 1

res = ave / cnt
print(res)

Submission status: Accepted

Solution code:
import math as m
import itertools as it

N = int(input())
xy = [[int(i) for i in input().split()] for j in range(N)]
sum_dis = 0
num = 0
for i in it.permutations(xy):
    for jth in range(len(i) - 1):
        sum_dis += m.sqrt(
            (i[jth][0] - i[jth + 1][0]) ** 2 + (i[jth][1] - i[jth + 1][1]) ** 2
        )
    num += 1
print(sum_dis / num)

Submission status: Accepted

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

ans = 0
for p in itertools.permutations(xy, n):
    for i in range(n-1):
        ans += math.sqrt((p[i][0]-p[i+1][0])**2 + (p[i][1]-p[i+1][1])**2)
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
#ABC145-C Average Length
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i], y[i] = map(int, input().split()) #空白で区切られたN回の入力。のやり方の一つ。

import math

def root_length(x0, y0, x1, y1):
    return math.sqrt((x1-x0)**2 + (y1-y0)**2)
ans = 0
for i in range(N-1):
    for j in range(i+1, N):
        ans += root_length(x[i],y[i],x[j],y[j])
ans *= 2 /N 
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

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

rr = list(itertools.permutations(route, N))

total = 0
for r in rr:
    for i in range(len(r) - 1):
        x = (r[i][0] - r[i+1][0]) ** 2
        y = (r[i][1] - r[i+1][1]) ** 2
        f = math.sqrt(x + y)
        total += f

print(total/len(rr))

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
for i in range(N):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1)

#print(x)
#print(y)

ans = 0

for j in range(N):
    for k in range(N):
        if(j == k):
            continue
        disx = x[k] - x[j]
        disy = y[k] - y[j]
        ans += ((disx ** 2) + (disy ** 2))**0.5

print(ans/N)

Submission status: Accepted

Solution code:
N = int(input())
x = []
y = []
SUM = 0
for loop in range(N):
    tmp_x, tmp_y = map(int,input().split())
    x.append(tmp_x)
    y.append(tmp_y)
for i in range(N-1):
    for j in range(i+1,N):
        SUM += ((x[j]-x[i])**2+(y[j]-y[i])**2)**0.5
ans = 2*SUM/N
print(ans)

Submission status: Accepted

Solution code:
import math

n = int(input())
x = []
y = []


arr = [i for i in range(1,n)]
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
  
count = 0
for i in range(n-1):
  for j in range(i+1,n):
    count += math.sqrt(((x[i]-x[j])**2)+((y[i]-y[j])**2))

print(count / n * 2)

Submission status: Accepted

Solution code:
def solve(points) -> float:
  def all_shuffled(xs):
    if len(xs) == 0:
      return [[]]

    ret = []
    for i in range(len(xs)):
      ret += [[xs[i]] + shuffled for shuffled in all_shuffled(xs[0: i] + xs[i + 1: ])]
    return ret

  n = len(points)

  factorial_n = 1
  for i in range(1, n + 1):
    factorial_n *= i

  dist_sum = 0.0
  for ps in all_shuffled(points):
    for i in range(n - 1):
      xi, yi = ps[i]
      xj, yj = ps[i + 1]
      dist_sum += ((xi - xj) ** 2 + (yi - yj) ** 2) ** (1/2)

  return dist_sum / factorial_n


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

print(solve(points))

Submission status: Accepted

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

ans=0
def dist(p1,p2):
	return ((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)**0.5

for i in range(n):
	for j in range(i+1,n):
		ans+=dist(xys[i],xys[j])
ans*=2
ans/=n
print(ans)

Submission status: Accepted

Solution code:
import math
from itertools import permutations

n = int(input())

verts = []

for _ in range(n):
	x, y = map(int, input().split())
	verts.append((x, y))

def get_dist(x0, y0, x1, y1):
	return math.sqrt(pow(x1 - x0, 2) + pow(y1 - y0, 2))

avg_dist = 0
den = 0
for permutation in permutations(verts, n):
	dist = 0
	# print(permutation)
	for i in range(1, len(permutation)):
		x1, y1 = permutation[i]
		x0, y0 = permutation[i-1]
		dist += get_dist(x0, y0, x1, y1)
	avg_dist += dist
	den += 1
print('%.10f'%(avg_dist/den))

Submission status: Accepted

Solution code:
import itertools
import math

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

combi = itertools.combinations(range(N), 2)


def dist(combi):
    t0 = towns[combi[0]]
    t1 = towns[combi[1]]
    d = math.sqrt((t0[0] - t1[0]) ** 2 + (t0[1] - t1[1]) ** 2)
    return d


dist_list = {}
for c in combi:
    key = '{0[0]}_{0[1]}'.format(sorted(c))
    dist_list[key] = dist(c)

def total_dist(perm):
    d = 0
    for p in zip(perm[:-1], perm[1:]):
        key = '{0[0]}_{0[1]}'.format(sorted(p))
        d += dist_list[key]
    return d


perm = itertools.permutations(range(N), N)

result = 0
count = 0
for p in perm:
    count += 1
    result += total_dist(p)

result /= count
print(result)

Submission status: Accepted

Solution code:
import math
n=int(input())
z=[list(map(int,input().split())) for _ in range(n)]
s=0
for i in range(n):
  for j in range(n):
    if i!=j:
      s+=math.sqrt((z[i][0]-z[j][0])**2+(z[i][1]-z[j][1])**2)
print(s/n)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = [0 for i in range(n)]
y = [0 for i in range(n)]
for _ in range(n):
  x[_], y[_] = list(map(int, input().split()))

sum_distance = 0

for i in range(n):
  for j in range(n):
    sum_distance += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    
print(sum_distance/n)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000000)
from itertools import count
from functools import lru_cache
from collections import defaultdict
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#


def main():
    N=ii()
    P = tuple(tuple(mis()) for _ in range(N))
    ans = 0
    def length(prv, nex):
        if prv is None:
            return 0
        else:
            return ((P[nex][0]-P[prv][0])**2 + (P[nex][1]-P[prv][1])**2) ** 0.5

    def rec(bf, val, prev):
        nonlocal ans
        if bf == 2**N-1:
            ans += val
        else:
            for i in range(N):
                b = 1 << i
                if not bf & b:
                    rec(bf | b, val + length(prev, i), i)

    rec(0, 0, None)

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

main()

Submission status: Accepted

Solution code:
#yandy
N = int(input())
 
paths = []
 
for _ in range(N):
    x, y = map(int, input().split())
    paths.append((x, y))
 
all_path_len = 0
 
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        xa, ya = paths[i]
        xb, yb = paths[j]
        all_path_len += ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
 
ans = all_path_len / N
 
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
 
n = int(input())
n_ = 1
for i in range(n):
    n_ *= i+1
c = [tuple(map(int,input().split())) for _ in range(n)]
tot = 0
 
def dis(c,x,y):
  x1,y1 = c[x]
  x2,y2 = c[y]
  return ((x1-x2)**2 + (y1-y2)**2)**.5
 
for l in permutations(range(n)):
    d = 0
    cur = l[0]
    for x in l:
        d += dis(c,cur,x)
        cur = x
    tot += d/n_
print(tot)

Submission status: Accepted

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

towns=list(range(n))
now=1
kaijou=[]
for i in range(1,9):
    now*=i
    kaijou.append(now)

from itertools import permutations
import math
for root in permutations(towns,n):
    ans+=sum([math.sqrt( ( x[root[i]]-x[root[i-1]])**2 +( y[root[i]]-y[root[i-1]])**2 ) for i in range(1,n)])
print(ans/kaijou[n-1] )

Submission status: Accepted

Solution code:
from itertools import permutations


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


n = int(input())
xy_array = [[int(x) for x in input().split()] for y in range(n)]
p = permutations([x for x in range(n)])

sum_distance = 0
for order in p:
    for index in range(n - 1):
        x1 = xy_array[order[index]][0]
        x2 = xy_array[order[index + 1]][0]
        y1 = xy_array[order[index]][1]
        y2 = xy_array[order[index + 1]][1]
        sum_distance += calc_distance(x1, y1, x2, y2)
tmp = 1
for i in range(2, n + 1):
    tmp *= i
print(sum_distance / tmp)

Submission status: Accepted

Solution code:
N = int(input())

paths = []

for _ in range(N):
    x, y = map(int, input().split())
    paths.append((x, y))

all_path_len = 0

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        xa, ya = paths[i]
        xb, yb = paths[j]
        all_path_len += ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5

ans = all_path_len / N

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
T = [[]*2]*N
for i in range(N):
  T[i] = list(map(int, input().split()))

L = 0
for i in itertools.permutations(T):
  for n in range(N-1):
    L = L + math.sqrt((i[n][0]-i[n+1][0])**2+(i[n][1]-i[n+1][1])**2)

print(L/math.factorial(N))

Submission status: Accepted

Solution code:
n = int(input())
xy = []
for i in range(n):
    xy.append(list(map(int, input().split())))
length = 0
for i in range(n):
    for j in range(i + 1, n):
        length += ((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2) ** 0.5
print(length / n * 2)

Submission status: Accepted

Solution code:
# coding: utf-8
import math

n = int(input())
points = []
combi_num = 1
for i in range(n):
    p = list(map(int, input().split()))
    points.append(p)
    combi_num *= i
#print(points)

total = 0
for i in range(n):
    for j in range(n):
        if i != j:
            k = math.sqrt((points[i][0]-points[j][0])*(points[i][0]-points[j][0]) + (points[i][1]-points[j][1])*(points[i][1]-points[j][1]))
            total += k
print(total/n)

Submission status: Accepted

Solution code:
n = int(input())
xy = []
for i in range(n):
    x,y = map(int, input().split())
    xy.append([x,y])
ans = 0    
for i in range(n):
    for j in range(n):
        ans += ((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)**0.5
        
print(ans/n)

Submission status: Accepted

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

dists = [[0] * n for _ in range(n)]
for i in range(n):
	for j in range(n):
		dists[i][j] = ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** (1 / 2)

ans = sum([sum(d) for d in dists]) / n
print(ans)