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 sys
import math
import itertools
import collections

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    N = NI()
    xy = [NLI() for _ in range(N)]
    
    ls = [p for p in range(N)]
    p_list = list(itertools.permutations(ls))
    
    full_course = ["" for _ in range(len(p_list))]
    
    for k in range(len(p_list)):
        distance = 0
        for l in range(N-1):
            departure = p_list[k][l] 
            goal = p_list[k][l+1]
            Xd = xy[departure][0]
            Yd = xy[departure][1]
            Xg = xy[goal][0]
            Yg = xy[goal][1]
            distance += ((Xd-Xg)**2 + (Yd-Yg)**2)**(1/2)
        full_course[k] = distance

    print(sum(full_course)/len(p_list))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

N = int(input())
town = {}
route = permutations(range(0,N))

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

Sum = 0

for v in route:
    for i in range(N-1):
        Sum += ((town[v[i+1]][0] - town[v[i]][0])**2 + (town[v[i+1]][1] - town[v[i]][1])**2)**(0.5)

ans = Sum/factorial(N)

print(ans)

Submission status: Accepted

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
ans=0
for i in permutations(range(n),n):
    for j in range(1,n):
        ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
for i in range(1,n+1):
    ans/=i
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import math
N = int(input())
x = [0] * N
y = [0] * N
al = 1
l = 0
for i in range(N):
    al *= (i+1)
    x[i], y[i] = map(int, input().split())

que = deque()
for i in range(N):
    que.append([i])
while que:
    seq = que.popleft()
    if len(seq) == N:
        for i in range(N-1):
            l += math.sqrt((x[seq[i+1]]-x[seq[i]]) ** 2 + (y[seq[i+1]]-y[seq[i]]) ** 2)
    else:
        for i in range(N):
            if i in seq:
                continue
            seq_next = seq + [i]
            que.append(seq_next)

print(l / al)

Submission status: Accepted

Solution code:
import math
import itertools

n = int(input())
data = []

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

cnt = 0

for a in itertools.permutations(range(n)):
  for j in range(n-1):
    cnt += ((data[a[j+1]][0]-data[a[j]][0])**2 + (data[a[j+1]][1]-data[a[j]][1])**2)**0.5

print(cnt / math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
xy = []
for _ in range(N):
    x, y = map(int, input().split())
    xy.append([x, y])

cnt = list(itertools.permutations(xy))
ans = []
for c in cnt:
    ky = []
    for n in range(N-1):
        k = ((c[n][0]-c[n+1][0])**2+(c[n][1]-c[n+1][1])**2)**(1/2)
        ky.append(k)
    ans.append(sum(ky))
print(sum(ans)/len(ans))

Submission status: Accepted

Solution code:
N = int(input())
XY = []
points = []
for i in range(N):
	points.append(i)
	x, y = list(map(int, input().split()))
	XY.append((x, y))

import math
import itertools
count = math.factorial(N)
line = 0
for pp in itertools.permutations(points, N):
	i = 0
	while i < N - 1:
		i1, i2 = pp[i], pp[i + 1]
		t = ((XY[i1][0] - XY[i2][0]) ** 2 + (XY[i1][1] - XY[i2][1]) ** 2) ** 0.5 
		line += t
		i += 1
ans = line / count
print(ans)

Submission status: Accepted

Solution code:
import itertools

n = int(input())

x_list = []
y_list = []
cnt = 0
distance = 0

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

for a in itertools.permutations(range(n)): #順列を生成して、それらに対して処理
    cnt += 1
    for i in range(len(a)-1):
        #　各順列に対する処理
        distance += ((x_list[a[i]]-x_list[a[i+1]])**(2) + (y_list[a[i]]-y_list[a[i+1]])**(2))**(1/2)
ans = distance/cnt
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
import math
import time
import statistics
import math
import itertools

# a = get_int()
def get_int():
    return int(input())
# a = get_string()
def get_string():
    return input()
# a_list = get_int_list()
def get_int_list():
    return [int(x) for x in input().split()]
# a_list = get_string_list():
def get_string_list():
    return input().split()
# a, b = get_int_multi()
def get_int_multi():
    return map(int, input().split())
# a_list = get_string_char_list()
def get_string_char_list():
    return list(str(input()))
# print("{} {}".format(a, b))
# for num in range(0, a):
# a_list[idx]
# a_list = [0] * a
'''
while (idx < n) and ():

    idx += 1
'''

def main():
    start = time.time()
    n = get_int()
    a = []
    ans = 0
    for i in range(n):
        a.append(get_int_list())

    count = 0
    for keiro in itertools.permutations(a):
        count += 1
        nagasa = 0
        for i in range(1,n):
            nagasa += math.sqrt((keiro[i][0] - keiro[i-1][0]) ** 2 + (keiro[i][1] - keiro[i-1][1]) **2)
        ans += nagasa
    print(ans / count)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import permutations as P
from math import sqrt as r

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans_sum = 0
town = list(P(list(range(N)), N))
Q = len(town)

for town in town:
    d = 0
    for i in range(N - 1):
        X = xy[town[i]][0] - xy[town[i + 1]][0]
        Y = xy[town[i]][1] - xy[town[i + 1]][1]
        d += r(X**2 + Y**2)
    #print(d)
    ans_sum += d

print(ans_sum/Q)

Submission status: Accepted

Solution code:
from itertools import combinations

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

Submission status: Accepted

Solution code:
def resolve():
    import itertools
    import math
    def distance(i, j):
        return math.sqrt((i[0]-j[0])**2+(i[1]-j[1])**2)

    n = int(input())
    l = list(range(n))
    X_Y = []
    for i in range(n):
        X_Y.append(list(map(int, input().split())))
    p_list = list(itertools.permutations(l, n))
    total = 0
    for p in p_list:
        p_t = 0
        for index in range(n-1):
            p_t += distance(X_Y[p[index]], X_Y[p[index+1]])
        total += p_t
    print(total/len(p_list))
resolve()

Submission status: Accepted

Solution code:
N = int(input())
xy = [list(map(int,input().split())) for i in range(N)]
print(sum(((xi-xj)**2 + (yi-yj)**2) **0.5 for xi,yi in xy for xj,yj in xy) / N)

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
x = [0]
y = [0]
for i in range(1,n+1):
    a,b = map(int,input().split())
    x.append(a)
    y.append(b)
    
num_list = [int(i) for i in range(1,n+1)]
keiro = []
for v in itertools.permutations(num_list, n):
    keiro.append(list(v))
kensu = math.factorial(n)
#print(keiro)
#print(kensu)
ans = 0
for i in range(kensu):
    for j in range(n-1):
        ans += math.sqrt((x[keiro[i][j]]-x[keiro[i][j+1]])**2+(y[keiro[i][j]]-y[keiro[i][j+1]])**2)
print(ans/kensu)

Submission status: Accepted

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
all_order=[]
def dfs(a):
  if len(a)==n:
    all_order.append(a)
  else:
    for i in range(n):
      if i in a:continue
      dfs(a+[i])
dfs([])
ans=0
for od in all_order:
  x,y=xy[od[0]]
  for i in od[1:]:
    nx,ny=xy[i]
    ans+=((x-nx)**2+(y-ny)**2)**0.5
    x,y=nx,ny
print(ans/len(all_order))

Submission status: Accepted

Solution code:
import itertools
import math

def dist(c1, c2):
    dist = math.sqrt((c2[0]-c1[0])**2 + (c2[1]-c1[1])**2)
    return dist

def solve():
    N = int(input())
    c = []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        c.append([x_tmp, y_tmp])
    l = [i for i in range(N)]

    sum_dist = 0
    ave_dist = 0
    for p in itertools.permutations(l):
        for i in range(len(p)-1):
            sum_dist += dist(c[p[i]], c[p[i+1]])
    ave_dist = sum_dist/len(list(itertools.permutations(l)))
    print(ave_dist)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import itertools

N = int(input())
dots = [tuple(map(int, input().split())) for _ in range(N)]
total_distance = 0
total_count = 0

for route in itertools.permutations(dots):
    for i in range(len(route)-1):
        x1, y1 = route[i]
        x2, y2 = route[i+1]

        total_distance += ((x2 - x1)**2 + (y2 - y1)**2)**0.5
    
    total_count += 1

ans = total_distance / total_count
print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

D = []
for i in range(n):
    for j in range(i+1,n):
        D.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)

# print(D)
ans = sum(D)*2/n
print(ans)

Submission status: Accepted

Solution code:
N=int(input())
lis=[tuple(map(int,input().split())) for _ in range(N)]
import itertools,math
p = itertools.permutations(list(range(N)))
sm=0

for v in p:
    #print(v)
    for k in range(N-1):
        xi,yi=lis[v[k]]
        xj,yj=lis[v[k+1]]
        #print(xi,yi,xj,yj)
        sm+=((xi-xj)**2+(yi-yj)**2)**(1/2)
print(sm/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
pos = []
for i in range(n):
    pos.append(list(map(int, input().split())))
perm = list(itertools.permutations(range(n)))
total = 0
for i in range(len(perm)):
    for j in range(1, len(perm[i])):
        pos_from = perm[i][j - 1]
        pos_to = perm[i][j]
        total += math.sqrt((pos[pos_to][0] - pos[pos_from][0]) ** 2 + (pos[pos_to][1] - pos[pos_from][1]) ** 2)
print(total / len(perm))

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())

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

l = range(n)

d_list =[]

for v in itertools.permutations(l):
    d = 0
    for i in range(n-1):
        f = v[i]
        t = v[i+1]
        d += math.sqrt((xy[t][0] - xy[f][0]) ** 2 + (xy[t][1] - xy[f][1]) ** 2)
    d_list.append(d)

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
L = []
for i in range(N):
    X, Y = map(int, input().split())
    L.append((X, Y))

total = 0
cnt = 0
for l in itertools.permutations(L):
    cnt += 1
    for i in range(1, N):
        total += math.sqrt((l[i][0]-l[i-1][0])**2 + (l[i][1]-l[i-1][1])**2)

print(total/cnt)

Submission status: Accepted

Solution code:
from itertools import permutations

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

perms = permutations(list(range(n)))
ans = 0
length = 0
for perm in perms:
    length += 1
    cur_i = 0
    tmp = 0
    for i in range(1, n):
        x = t[perm[cur_i]][0] - t[perm[i]][0]
        x = x**2
        y = t[perm[cur_i]][1] - t[perm[i]][1]
        y = y**2
        tmp += (x + y)**0.5
        cur_i = i
    ans += tmp
print(ans / length)

Submission status: Accepted

Solution code:
from itertools import permutations
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
r = []
for pp in permutations(P):
    t = 0
    for i in range(1, N):
        t += ((pp[i][0]-pp[i-1][0])**2 + (pp[i][1]-pp[i-1][1])**2)**(0.5)
    r.append(t)
print(sum(r)/len(r))

Submission status: Accepted

Solution code:
def dist(x0, y0, x1, y1):
    from math import sqrt
    return sqrt((x1-x0)**2 + (y1-y0)**2)

from itertools import permutations

N = int(input())
points = [tuple(map(int, input().split())) for _ in range(N)] #; print(points)

dsum = 0
for i, j in permutations(points, 2):
    dsum += dist(*i, *j)
print(dsum/N)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
twn = [list(map(int, input().split())) for _ in range(n)]
twnst = list(itertools.permutations(twn))
dstttl = 0
for i in twnst:
    for j in range(0, len(i) - 1):
        dstttl += (abs(i[j][0] - i[j+1][0])**2 + abs(i[j][1] - i[j+1][1])**2)**0.5
print(dstttl / len(twnst))

Submission status: Accepted

Solution code:
import math

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

count = N * (N - 1) // 2
t = 0.0

for i in range(N):
    for j in range(i + 1, N):
        x1 = XY[i][0]
        y1 = XY[i][1]
        x2 = XY[j][0]
        y2 = XY[j][1]

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

print(t / count * (N - 1))

Submission status: Accepted

Solution code:
import math
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
DONE = (1 << N) - 1

ds = []
todo = [(0, i, (1 << i)) for i in range(N)]
while todo:
    d, i, state = todo.pop()
    x, y = P[i]
    for ni in range(N):
        if state & (1 << ni):
            continue
        nx, ny = P[ni]
        nd = d + math.sqrt((x - nx) ** 2 + (y - ny) ** 2)
        nstate = state | (1 << ni)
        if nstate == DONE:
            ds.append(nd)
        else:
            todo.append((nd, ni, nstate))
ans = math.fsum(ds) / len(ds)
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations as per
n=int(input())
ans=[]
l=list(per(list(range(1,n+1))))
xy=[[] for i in range(n+1)]
for i in range(n):
    x,y=map(int,input().split())
    xy[i+1].append(x)
    xy[i+1].append(y)
def f(x):
    m=1
    while x>0:
        m*=x
        x=x-1
    return m
for i in range(f(n)):
    dis=0
    for j in range(n-1):
        dis+=((xy[l[i][j]][0]-xy[l[i][j+1]][0])**2+(xy[l[i][j]][1]-xy[l[i][j+1]][1])**2)**(0.5)
    ans.append(dis)
print(sum(ans)/f(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import product, combinations,permutations
from copy import deepcopy
import sys
from math import sqrt
sys.setrecursionlimit(4100000)



if __name__ == '__main__':
    N = int(input())
    xy = []
    for _ in range(N):
        x, y = map(int, input().split())
        xy.append([x, y])
    
    visit_perm = list(range(N))
    sum_dist = 0
    cnt = 0
    for v in permutations(visit_perm):
        cnt += 1
        prev = -1
        for i, p in enumerate(v):
            if i==0:
                prev = [xy[p][0], xy[p][1]]
            else:
                sum_dist += sqrt((xy[p][0]-prev[0])**2+(xy[p][1]-prev[1])**2)
    print(sum_dist/cnt)

Submission status: Accepted

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

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

print(sum(l)/N)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
R = np.array([list(map(int,input().split())) for n in range(N)])
print(sum(np.linalg.norm(i-j) for i in R for j in R)/N)

Submission status: Accepted

Solution code:
import itertools
import numpy as np
import math

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

lis = [x for x in range(n)]

p_list = itertools.permutations(lis)

s = 0

for one_case in p_list:
    prev = 0
    for i in range(n):
        if i == 0:
            prev = one_case[0]
        else:
            s += np.sqrt((xy[one_case[i]][0] - xy[prev][0])**2 + (xy[one_case[i]][1] - xy[prev][1])**2)
            prev = one_case[i]
print(s/math.factorial(n))

Submission status: Accepted

Solution code:
def dist (s1,s2):
    x1=s1[0]
    y1=s1[1]
    x2=s2[0]
    y2=s2[1]
    a=(x1-x2)**2+(y1-y2)**2
    return pow(a,0.5)
arr=[]
n=int(input())
for _ in range(n):
    inp=list(map(int,input().split()))
    arr.append((inp[0],inp[1]))
ans=0
for i in range(len(arr)):
    for j in range(len(arr)):
        ans+=dist(arr[i],arr[j])
print (ans/n)

Submission status: Accepted

Solution code:
import math
n=int(input())
s=[]
for i in range(n):
  m=[int(x) for x in input().split()]
  s.append(m)
d=0
for i in range(n-1):
  for j in range(i+1,n):
    d+=math.sqrt((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)
ans=d*2/n
print(ans)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    n = int(input())
    path = list(itertools.permutations(list(range(n))))
    path_len = len(path)
    place = [list(map(int, input().split())) for i in range(n)]
    ans = 0
    for i in path:
        q = 0
        for k in range(n-1):
            q += ( (place[i[k+1]][0] - place[i[k]][0])**2 + (place[i[k+1]][1] - place[i[k]][1])**2 )**(1/2)
        ans += q
    print(ans/path_len)


if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import math
import itertools

n = int(input())
l = []
for _ in range(n):
  a = list(map(int,input().split()))
  l.append(a)

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

result = dis/math.factorial(n)

print(result)

Submission status: Accepted

Solution code:
import sys
import collections
import bisect


def main():
    n = int(input())
    under = 1
    for i in range(1, n + 1):
        under *= i

    xyList = [list(map(int, input().split())) for _ in range(n)]
    xyListSum = 0
    for xn in range(1, n):
        for yn in range(xn + 1, n + 1):
            leng = ((xyList[xn-1][0] - xyList[yn-1][0]) **
                    2 + (xyList[xn - 1][1] - xyList[yn - 1][1]) ** 2) ** 0.5
            xyListSum += leng * 2
    print(xyListSum / n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

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


dist = 0
f = 0
for v in itertools.permutations(l, n):
    f += 1
    for i in range(1, n):
        x1, y1 = v[i-1]
        x2, y2 = v[i]
        dist += ((x1-x2)**2 + (y1-y2)**2)**0.5
res = round(dist/f, 10)
print(res)

Submission status: Accepted

Solution code:
class Town:
  def __init__(self,x,y):
    self.x = x
    self.y = y

from itertools import permutations

N = int(input())
towns = []
for n in range(N):
  d = input().split()
  x, y = map(int, d)
  towns.append(Town(x,y))

roots = list(permutations(towns))

distances = 0
for root in roots:
  distance = 0
  for i in range(len(root) - 1 ):
    start = root[i]
    end = root[i + 1]
    distance += ((start.x - end.x) ** 2 + (start.y - end.y) ** 2) ** (1 / 2)
  distances += distance

average = distances / len(roots)
print(average)

Submission status: Accepted

Solution code:
import itertools
import math
N=int(input())
z=[]
for _ in range(N):
    z.append(list(map(int,input().split())))
sum=0
for per in itertools.permutations(list(range(N))):
    for i in range(N-1):
        sum+=math.sqrt((z[per[i]][0]-z[per[i+1]][0])**2+(z[per[i]][1]-z[per[i+1]][1])**2)
ans=sum/math.factorial(N)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from itertools import permutations
    from math import hypot

    N = int(input())

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

    ans = 0
    for perm in permutations(xys, r=2):
        x1, y1 = perm[0]
        x2, y2 = perm[1]
        d = hypot(x2 - x1, y2 - y1)
        ans += d
    ans /= N

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())

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

pmt = list(itertools.permutations(range(0, n)))

dis_sum = 0

for i in pmt:
    dis = 0
    for j in range(n-1):
        x1, y1 = location[i[j]]
        x2, y2 = location[i[j+1]]
        dis += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    dis_sum += dis

print(dis_sum/len(pmt))

Submission status: Accepted

Solution code:
from itertools import combinations
N = int(input())
P = [tuple(map(int,input().split())) for _ in range(N)]

total = sum(((x0-x1)**2+(y0-y1)**2)**(1/2) for (x0,y0),(x1,y1) in combinations(P,2))

print(2*total/N)

Submission status: Accepted

Solution code:
# 町a,b(a < b)の距離をあらかじめdictionaryで保存しておく
# そのうえで、全探索可能

import sys
readline = sys.stdin.readline

N = int(readline())
town = [None] * N
for i in range(N):
  town[i] = tuple(map(int,readline().split()))

from collections import defaultdict
dist = defaultdict(float)

for i in range(N - 1):
  for j in range(i + 1, N):
    ix,iy = town[i]
    jx,jy = town[j]
    dist[(i,j)] = ((ix - jx) ** 2 + (iy - jy) ** 2) ** 0.5
    
# 距離を求めたので、あとは全パターン検索
ans = 0
import itertools
for perm in itertools.permutations(range(N)):
  d = 0
  for i in range(1, len(perm)):
    a,b = perm[i - 1],perm[i]
    if a > b:
      a,b = b,a
    d += dist[(a, b)]
  ans += d
  
pat = 1
for i in range(2, N + 1):
  pat *= i
print(ans / pat)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
data = [[int(e) for e in input().split(" ")] for _ in range(N)]

ans = 0
cnt = 0
for path in itertools.permutations([i for i in range(N)]):
    dis = 0
    cnt += 1
    for i in range(N - 1):
        u = path[i]
        v = path[i + 1]

        dis += ((data[u][0] - data[v][0]) ** 2 +
                (data[u][1] - data[v][1]) ** 2)**(1 / 2)

    ans += dis

ans /= cnt
print(ans)

Submission status: Accepted

Solution code:
import itertools

# 2点間距離を求める
def length(a, b):
    x = (a[0] - b[0])**2
    y = (a[1] - b[1])**2
    
    return (x + y)**(1/2)

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

machi = [n for n in range(N)]

parms = list(itertools.permutations(machi, N))
ans = 0

for parm in parms:
    temp = 0
    for i in range(len(parm)-1):
        a = parm[i]
        b = parm[i+1]
        temp += length(zahyo[a], zahyo[b])
        
    ans += temp / len(parms)
    
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import itertools

n=int(input())
ab = []
for _ in range(n):
    a, b = (int(x) for x in input().split())
    ab.append([a, b])

narabi = [0+i for i in range(n)]

ans = 0
count = 0
for v in itertools.permutations(narabi, n):
    count += 1
    tmp_len = 0
    for i in range(1,n):
        x, y = abs(ab[v[i-1]][0]-ab[v[i]][0])**2, abs(ab[v[i-1]][1]-ab[v[i]][1])**2
        tmp_len += (x + y)**0.5
    ans += tmp_len

print(ans/count)

Submission status: Accepted

Solution code:
from itertools import permutations

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

s = 0
c = 0
for perm in permutations(range(N), N):
    c += 1
    for i in range(N-1):
        s += abs(points[perm[i]] - points[perm[i+1]])

print(s / c)

Submission status: Accepted

Solution code:
n = int(input())
a = [list(map(int,input().split()))for _ in range(n)]
ans = 0
for x1,y1 in a:
    for x2,y2 in a:
        ans += ((x1-x2)**2+(y1-y2)**2)**0.5
print(ans/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
N = int(input())
data = []
for _ in range(N):
    x, y = map(int, input().split())
    data.append((x,y))
res = 0
for a in permutations(data,N):
    x0, y0 = a[0]
    for x, y in a[1:]:
        res += ((x-x0)**2 + (y-y0)**2)**(0.5)
        x0, y0 = x, y

print(res/factorial(N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# モジュールのインポート
import math
import itertools

# 標準入力を取得
N = int(input())
x, y = [], []
for n in range(N):
    x_n, y_n = list(map(int, input().split()))
    x.append(x_n)
    y.append(y_n)

# 求解処理
def get_distance(i: int, j: int) -> float:
    return math.sqrt(math.pow(x[i] - x[j], 2) + math.pow(y[i] - y[j], 2))

ans = 0
for path in itertools.permutations(range(N), N):
    distance = 0
    for i in range(N - 1):
        distance += get_distance(path[i], path[i + 1])
    ans += distance
ans /= math.factorial(N)

# 結果出力
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
xy = []
for _ in range(N):
    xi, yi = map(int, input().split())
    xy.append([xi, yi])

# print(xy)

sum_dist = 0

# 第二引数を指定しなければ全ての要素の順列を返す
for perm in itertools.permutations(range(N)):
    dist = 0
    for i in range(1, N):
        dist += math.sqrt((xy[perm[i]][0] - xy[perm[i - 1]][0]) **
                          2 + (xy[perm[i]][1] - xy[perm[i - 1]][1])**2)
    # print(sum_dist)
    sum_dist += dist

ans = sum_dist / math.factorial(N)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
x = [0]*N
y = [0]*N
dist = [[0]*N]*N
ans = 0

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

for i in range(N):
  for j in range(N):
    dist[i][j]=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
    ans += dist[i][j]

print(ans/N)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
x=[]
y=[]
for i in range(n):
    x0, y0 = map(int,input().split())
    x.append(x0)
    y.append(y0)
    
ls = list(itertools.permutations(range(1,n+1)))

dist = 0
for i in ls:

    p0 = i[0]-1
    for j in range(1,len(i)):
        p1 = i[j]-1
        dist += ((x[p0]-x[p1])**2 + (y[p0]-y[p1])**2)**0.5
        p0=p1
        # print(dist)
    # print( )
        

print(dist/(len(ls)))

Submission status: Accepted

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

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

print(dist/n)

Submission status: Accepted

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

import itertools
pattern = itertools.permutations(xy, n)

import numpy as np

distances = []
for p in pattern:
    distance = 0
    for i, (x, y) in enumerate(p):
        if i == 0:
            base = (x, y)
            continue
    
        b_x, b_y = base
        d2 = (b_x - x) ** 2 + (b_y - y) ** 2
        d = np.sqrt(d2)
        distance += d
    
        base = (x, y)

    distances.append(distance)

print(np.mean(distances))

Submission status: Accepted

Solution code:
import itertools

N = int(input())
l = []
kyori = []

for _ in range(N):
    xy = list(map(int, input().split()))
    l.append(xy)

for i in itertools.combinations(l,2):
    t = ((i[0][0]-i[1][0])**2 + (i[0][1] - i[1][1])**2)**0.5
    kyori.append(t)

print((N-1)*sum(kyori)/len(kyori))

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

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

def dist_calc(i,j):
  return sqrt(pow(position[i][0]-position[j][0],2)
              +pow(position[i][1]-position[j][1],2))

ans = 0
mean = 0
for tmp in permutations(range(n)):
  for j in range(n-1):
    ans += dist_calc(tmp[j],tmp[j+1])
  mean += 1
print(ans/mean)

Submission status: Accepted

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


total_distance = 0
list_keiro = []
for team in itertools.permutations(range(n)):
    list_keiro.append(team)

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

for i in list_keiro:
  dis_tmp = 0
  for j in range(n-1):
    dis_tmp += distance(xy[i[j]][0],xy[i[j+1]][0],xy[i[j]][1],xy[i[j+1]][1])
  total_distance += dis_tmp

print(total_distance / len(list_keiro))