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 bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
#H,N = LI()
_XY = [LI() for _ in range(N)]
# X,Y = zip(*XY)
XY = np.array(_XY)
#C = np.zeros(N + 1)
# print(XY)

# print(np.linalg.norm(XY[1]-XY[0]))

def calcdis(p1,p2):
    return np.linalg.norm(p2-p1)

ans = []
for i in range(N):
    tmp = 0
    for j in range(N):
        if not i==j:
            # print(i,j)
            tmp += calcdis(XY[i],XY[j])
    ans.append(tmp)
print(np.average(ans))

# if ans:
#     print('Yes')
# else:
#     print('No')

Submission status: Accepted

Solution code:
import itertools

n=int(input())
l=[]
for i in range(n):
    x=[int(j) for j in input().rstrip().split()]
    l.append(x)


cnt=0
ans=0
num=[i for i in range(n)]
for i in itertools.permutations(num,n):
    cnt+=1
    for j in range(n-1):
        ans+=((l[i[j]][0]-l[i[j+1]][0])**2+(l[i[j]][1]-l[i[j+1]][1])**2)**0.5
print(ans/cnt)

Submission status: Accepted

Solution code:
n = int(input())
xy = [list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
count = 0
dist = 0
for l in list(permutations(xy)):
    tmp = 0
    for i in range(len(l)-1):
        tmp += ((l[i+1][0]-l[i][0])**2+(l[i+1][1]-l[i][1])**2)**0.5
    dist += tmp
    count += 1

print(dist/count)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt
n = int(input())
positions = [tuple(map(int, input().split())) for _ in range(n)]


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


ans = 0
count = 0
for tmp in permutations(range(n)):
    for i in range(len(tmp) - 1):
        ans += calc_distance(tmp[i], tmp[i + 1])
    count += 1

print(ans / count)

Submission status: Accepted

Solution code:
import itertools

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

town_name = []
for i in range(n):
    tmp_str_town_name = str(i)
    town_name.append(tmp_str_town_name)

p = list(itertools.permutations(town_name, n))

distance = 0
for i in range(len(p)):
    one_path = p[i]
    for j in range(n - 1):
        l = int(one_path[j])
        r = int(one_path[j + 1])
        lx, ly = town_map[l]
        rx, ry = town_map[r]
        distance += ((rx - lx)**2 + (ry - ly)**2) ** (1/2)

print(distance / len(p))

Submission status: Accepted

Solution code:
from itertools import permutations
import math

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

sum_roots = 0
for points in permutations(XY):
    for point_idx in range(1, N):
        before_x = points[point_idx-1][0]
        before_y = points[point_idx-1][1]
        x = points[point_idx][0]
        y = points[point_idx][1]
        sum_roots += math.sqrt((x-before_x) ** 2 + (y-before_y)**2)

print(sum_roots/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools
def distance(a,b):
    return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5
n = int(input())
a = [tuple(map(int,input().split())) for _ in range(n)]
l = []
for m in list(itertools.permutations(a)):
    d = 0
    for i in range(n-1):
        d += distance(m[i],m[i+1])
    l.append(d)
print(sum(l)/len(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
lst = []
for _ in range(n):
  lst.append(list(map(int, input().split())))
#print(lst)

cases = list(itertools.permutations(list(range(n))))
#print(cases)
length = 0
for case in cases:
  for i in range(n - 1):
    pos_1 = case[i]
    pos_2 = case[i + 1]
    position_1 = lst[pos_1]
    position_2 = lst[pos_2]
    #print(position_1)
    length += ((position_1[0] - position_2[0]) ** 2 + (position_1[1] - position_2[1]) ** 2) ** 0.5
length = length / len(cases)
print(length)

Submission status: Accepted

Solution code:
# abc145_c.py
# https://atcoder.jp/contests/abc145/tasks/abc145_c

# C - Average Length /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 300点

# 問題文
# 座標平面上に N個の町があります。
# 町 i は、座標 ( xi , yi ) に位置しています。町 i と町 j の間の距離は √(xi−xj)2+(yi−yj)2です。
# これらの町を全て 1回ずつ訪れるとき、町を訪れる経路は全部で N! 通りあります。
# 1 番目に訪れる町から出発し、2 番目に訪れる町、3 番目に訪れる町、…、を経由し、N 番目に訪れる町に到着するまでの移動距離
#  (町から町への移動は直線移動とします) を、その経路の長さとします。これらの N!通りの経路の長さの平均値を計算してください。

# 制約
#     2≤N≤8
#     −1000≤xi≤1000
#     −1000≤yi≤1000
#     (xi,yi)≠(xj,yj)
#     ( i≠jのとき)
#     (21:12 追記) 入力中の値はすべて整数である。

# 入力
# 入力は以下の形式で標準入力から与えられる。
# N
# x1 y1
# :
# xN yN

# 出力
# 経路の長さの平均値を出力せよ。 出力は、ジャッジの出力との絶対誤差または相対誤差が 10−6以下のとき正解と判定される。

# 入力例 1
# 3
# 0 0
# 1 0
# 0 1

# 出力例 1
# 2.2761423749

# 町を訪れる経路は 1→ 2 → 3 , 1 → 3 → 2 , 2 → 1 → 3 , 2 → 3 → 1 , 3 → 1 → 2 , 3 → 2 → 1 の 6通りです。
# このうち、経路 1→ 2 → 3 の長さは、√(0−1)2+(0−0)2+√(1−0)2+(0−1)2=1+√2となります。
# 同様に他の経路についても長さを計算すると、経路の長さの平均値は、(1+√2)+(1+√2)+(2)+(1+√2)+(2)+(1+√2)6=2.276142...
# であると分かります。

# 入力例 2
# 2
# -879 981
# -866 890

# 出力例 2
# 91.9238815543

# 町を訪れる経路は 1→ 2 , 2 → 1 の 2通りありますが、これらの経路の長さは一致します。

# 入力例 3
# 8
# -406 10
# 512 859
# 494 362
# -955 -475
# 128 553
# -986 -885
# 763 77
# 449 310

# 出力例 3
# 7641.9817824387


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    N = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    valueses = list()
    for i in range(N):
        valueses.append(list(map(int, lines[i+1].split())))

    su = 0

    for i in range(N):
        for j in range(i+1, N):
            log(f'i=[{i}], j=[{j}]')
            xi, yi = valueses[i]
            xj, yj = valueses[j]
            distance = ((xi-xj)**2 + (yi-yj)**2) ** 0.5
            log(f'distance=[{distance}]')
            su += distance

    result = su / N * 2

    return [result]


# 引数を取得
def get_input_lines():
    line = input()
    N = int(line)
    lines = list()
    lines.append(line)
    for _ in range(N):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['3', '0 0', '1 0', '0 1']
        lines_export = [2.2761423749]
    if pattern == 2:
        lines_input = ['2', '-879 981', '-866 890']
        lines_export = [91.9238815543]
    if pattern == 3:
        lines_input = ['8', '-406 10', '512 859', '494 362', '-955 -475', '128 553', '-986 -885', '763 77', '449 310']
        lines_export = [7641.9817824387]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines()
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def resolve():
    import itertools
    import math
    N = int(input())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, input().split())
        X.append(x)
        Y.append(y)
    ans = 0
    ichi = 0
    for i in itertools.permutations(range(1, N+1)):
        count = 0
        for p in range(N-1):
            count += math.sqrt((X[i[p+1]-1]-X[i[p]-1])**2+(Y[i[p+1]-1]-Y[i[p]-1])**2)
        ans += count
        ichi += 1
    print(ans/ichi)
resolve()

Submission status: Accepted

Solution code:
import itertools

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

s = [i for i in range(n)]

path = list(itertools.permutations(s, len(s)))

ans = 0

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

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = inp()
xy = inpll(n)

sum = 0
l = list(itertools.permutations(range(n),n))
for i in range(len(l)):
    for j in range(1,len(l[i])):
        sum += math.sqrt((xy[l[i][j]][0] - xy[l[i][j - 1]][0]) ** 2 + (xy[l[i][j]][1] - xy[l[i][j - 1]][1]) ** 2)

print(sum / len(l))

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
#n, m = map(int, input().split())
#hl = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
total = 0
townnum = [i for i in range(n)]
for v in itertools.permutations(townnum):
    for j in range(1, n):
        cur = l[v[j]]
        bef = l[v[j-1]]
        total += math.sqrt((cur[0]-bef[0])**2+(cur[1]-bef[1])**2)
ans = total/math.factorial(n)
print('{:.9f}'.format(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N=int(input())
X=[0 for _ in range(N)]
Y=[0 for _ in range(N)]
for i in range(N):
  X[i],Y[i] = map(int, input().split())
s=0
for i in range(N):
  for j in range(N):
    if not i==j:
      s+=math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)*math.factorial(N-1)
print(s/math.factorial(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from itertools import permutations

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

ave = 0

for p in permutations(coor, n):
    for i in range(n-1):
        ave += math.sqrt((p[i][0] - p[i+1][0])**2 + (p[i][1] - p[i+1][1])**2)

ans = ave/math.factorial(n)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from itertools import combinations

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

roots = list(combinations(range(0,N),2))

sum_r = 0
for t, nt in roots:
  sum_r += math.sqrt((xy[t][0] - xy[nt][0])**2 + (xy[t][1] - xy[nt][1])**2)
  
res = 2*sum_r/N
print(res)

Submission status: Accepted

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

ans = 0
for i in range(n):
  for j in range(n):
    if i == j: continue
    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())
xy=[list(map(int,input().split())) for i in range(N)]
print(sum(((xi-xj)**2+(yi-yj)**2)**.5 for xi,yi in xy for xj,yj in xy)/N)

Submission status: Accepted

Solution code:
import numpy as np
import statistics
N = int(input())
XY = np.array([tuple(map(int, input().split())) for i in range(N)])
ans = 0
for i in range(N):
    av = statistics.mean([np.linalg.norm(XY[i]-XY[j]) for j in range(N)])
    ans += av
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

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

res = 0
cnt = 0
for pattern in itertools.permutations(cities, len(cities)):
    cnt += 1
    for i in range(n - 1):
        res += math.sqrt(
            (dots[pattern[i]][0] - dots[pattern[i + 1]][0]) ** 2
            + (dots[pattern[i]][1] - dots[pattern[i + 1]][1]) ** 2)

print(res / cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    XY = []
    for _ in range(N):
        XY.append(list(map(int, input().split())))
    import itertools
    import math
    total = 0
    for order in itertools.permutations(list(range(N))):
        posx, posy = XY[order[0]]
        dist = 0
        for i in range(1, N):
            nxtx, nxty = XY[order[i]]
            dist += math.sqrt((nxtx-posx)**2+(nxty-posy)**2)
            posx, posy = nxtx, nxty
        total += dist
    print(total/math.factorial(N))
    

    
if '__main__' == __name__:
    resolve()

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
from itertools import permutations
import math
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    X = []
    Y = []
    for _ in range(N):
        x, y = map(int, readline().split())
        X.append(x)
        Y.append(y)

    total = 0
    for i in permutations(range(N)):
        for j in range(1,N):
            total += math.sqrt((X[i[j]]-X[i[j-1]])**2 + (Y[i[j]]-Y[i[j-1]])**2)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math

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

lis = [x for x in range(N)]
permutations_lis = itertools.permutations(lis)

dis = 0
for one_case in permutations_lis:
    for i in range(1,N):
        dis += ((ls2[one_case[i]][0]-ls2[one_case[i-1]][0])**2+(ls2[one_case[i]][1]-ls2[one_case[i-1]][1])**2)**(1/2)
    
print(dis/(math.factorial(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())
answer=0
kaijou=1
junretu=0
for i in range(2,N+1):
  kaijou*=i
junretu=int(N*(N-1)/2)
a=int(kaijou*(N-1)/(junretu*2))

for i in range(N):
  for j in range(N):
    if i!=j:
      answer+=((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print((answer*a)/kaijou)

Submission status: Accepted

Solution code:
N=int(input())
X=[list(map(int,input().split())) for i in range(N)]
print(2/N*sum([sum([(l-m)**2for l,m in zip(X[i],X[j])])**0.5for j in range(N) for i in range(N) if i<j ]))

Submission status: Accepted

Solution code:
import itertools
import math

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

A = list(itertools.permutations(list(range(n))))
ans = 0
for a in A:
    for i in range(len(a)-1):
        ans += math.sqrt((D[a[i]][0]-D[a[i+1]][0])**2+(D[a[i]][1]-D[a[i+1]][1])**2)

print(ans/len(A))

Submission status: Accepted

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

l = [i for i in range(N)]
ssum = 0
for v in itertools.permutations(l):
  distance = 0
  pre = X[v[0]]
  for n in v:
    distance += math.sqrt((pre[0]-X[n][0])**2+(pre[1]-X[n][1])**2)
    pre = X[n]
  ssum += distance

print(ssum/math.factorial(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())
Sum=0
for i in range(n):
  for j in range(n):
    Sum += ((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
print(Sum/n)

Submission status: Accepted

Solution code:
import itertools

N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
ans=0
NP=list(itertools.permutations([i for i in range(N)],N))

temp=0

for np in NP:
	for i in range(0,len(np)-1):
		temp+=((XY[np[i]][0]-XY[np[i+1]][0])**2+(XY[np[i]][1]-XY[np[i+1]][1])**2)**.5
	ans+=temp
	temp=0

print(ans/len(NP))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
xy = [None]*n
for i in range(n):
    xy[i] = tuple(map(int, input().split()))

from itertools import permutations
ans = 0
num = 0
for p in permutations(range(n)):
    val = 0
    prv = p[0]
    for i in p[1:]:
        val += ((xy[i][0]-xy[prv][0])**2 + (xy[i][1]-xy[prv][1])**2) ** 0.5
        prv = i
    ans += val
    num += 1
print(ans/num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    town = [LI() for _ in range(n)]
    way = list(itertools.permutations(range(n), n))
    ans = 0
    for w in way:
        for i in range(n-1):
            x1 = town[w[i]][0]
            y1 = town[w[i]][1]
            x2 = town[w[i+1]][0]
            y2 = town[w[i+1]][1]
            ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
    ans /= len(way)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

cal_dist = lambda x,y: sqrt((x[0]-y[0])**2+(x[1]-y[1])**2)

def calc_total(route):
  total=0
  for i in range(1,len(route)):
    total+=cal_dist(X[route[i]],X[route[i-1]])
  return total

SUM=0
for p in permutations(range(N)):
  SUM += calc_total(p)

print(SUM/factorial(N))

Submission status: Accepted

Solution code:
import math

N = int(input())
List = []
Length = 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):
        Length += math.sqrt((List[i][0]-List[j][0])**2+(List[i][1]-List[j][1])**2)
        
print(Length*2/N)

Submission status: Accepted

Solution code:
import itertools
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  a.append((x,y))
num=0
count=0
for i in itertools.permutations(range(n),n):
  s=list(i)
  num+=1
  for j in range(n-1):
    count+=((a[s[j+1]][0]-a[s[j]][0])**2+(a[s[j+1]][1]-a[s[j]][1])**2)**(0.5)
print(count/num)

Submission status: Accepted

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

def dist(a,b) :
    return math.sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)

order_num = 1
order = list(itertools.permutations(range(n)))
for i in range(1,n+1) :
    order_num *= i

dist_list = []
for i in range(order_num) :
    total = 0
    for j in range(n-1) :
        prev = order[i][j]
        next = order[i][j+1]
        total += dist(city[next], city[prev])
    dist_list.append(total)
print(sum(dist_list)/order_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial as fact
N = int(input())
towns = [list(map(int, input().split())) for _ in range(N)]
acc = 0
for p in permutations(range(N), N):
    for i in range(N - 1):
        t1, t2 = towns[p[i]], towns[p[i + 1]]
        acc += ((t1[0] - t2[0]) ** 2 + (t1[1] - t2[1]) ** 2) ** .5
print(acc / fact(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
  for j in range(i+1, n):
    cnt += math.sqrt((a[i][0] - a[j][0]) ** 2 + (a[i][1] - a[j][1]) ** 2)
print(cnt * 2 / n)

Submission status: Accepted

Solution code:
import itertools
import math

def dist(x0, y0, x1, y1):
  ans = math.sqrt((x0-x1)**2 + (y0-y1)**2)
  return ans

N = int(input())
x = [0] * N 
y = [0] * N

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

goukei = 0

jr = list(itertools.permutations(range(N), N)) #jr=順列
#print(jr[1])
#print(type(jr[1]))
#print(jr[1][1])
#print(type(jr[1][1]))

for i in range(len(jr)):
  for j in range(N-1):
    goukei += dist(x[jr[i][j]], y[jr[i][j]], x[jr[i][j+1]], y[jr[i][j+1]])
print(goukei/len(jr))

Submission status: Accepted

Solution code:
from itertools import permutations

def dist(x0, y0, x1, y1):
    ans = ((x0 - x1) ** 2 + (y0 - y1) ** 2) ** (0.5)
    return ans

def resolve():
    N = int(input())
    x, y, = [], []
    for i in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        x.append(x_tmp)
        y.append(y_tmp)
    ans = 0
    ls = list(permutations(list(range(N)), N))
    for l in ls:
        for i in range(len(l)-1):
            ans += dist(x[l[i]], y[l[i]], x[l[i+1]], y[l[i+1]])

    print(ans / len(ls))
    return

resolve()

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
lis = list(itertools.permutations(range(n),n))

al=0
for elem in lis:
    [al := al + math.sqrt( (x[elem[i]]-x[elem[i+1]])**2 +  (y[elem[i]]-y[elem[i+1]])**2) for i in range(n-1)]

print(al/len(lis))

Submission status: Accepted

Solution code:
import itertools

n = int(input())

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

total = 0
num = [i for i in range(n)]
for v in itertools.permutations(num, n):
    d = 0
    for i in range(n-1):
        cf, ct = v[i], v[i+1]
        d += ((x[ct] - x[cf])**2 + (y[ct] - y[cf])**2)**0.5
    total += d
for i in range(n, 1, -1):
    total /= i
print(total)

Submission status: Accepted

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

l = []

for i in range(n):
    ans = 0
    for j,k in s:
        a = s[i][0] - j
        b = s[i][1] - k
        ans += numpy.sqrt(a**2 + b**2)
    l.append(ans)

print(sum(l)/n)

Submission status: Accepted

Solution code:
import math
import itertools

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

N = int(input())
Cord = []
ls = list(itertools.permutations(range(N)))
for _ in range(N):
    Cord.append(tuple(map(int,input().split())))
ans = 0
for l in ls:
    for i in range(N-1):
        ans+=distance(Cord[l[i]],Cord[l[i+1]])
print(ans/len(ls))

Submission status: Accepted

Solution code:
# coding: utf-8
import itertools
import math
# 人の数
N = int(input())
zahyo = []
for _ in range(N):
    zahyo.append(tuple(map(int, input().split(" "))))


def distance(zahyo1, zahyo2):
    return math.sqrt(pow(zahyo1[0] - zahyo2[0], 2) + pow(zahyo1[1] - zahyo2[1], 2))

dis = 0
for jyun in itertools.permutations(range(N)):
    for i in range(N-1):
       dis += distance(zahyo[jyun[i]], zahyo[jyun[i+1]])
print(dis / math.factorial(N))

Submission status: Accepted

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

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

Submission status: Accepted

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


def main():
  N = int(input())
  xy = [tuple(map(int, input().split())) for _ in range(N)]

  sum_ = 0
  for order in itertools.permutations(range(N)):
    for i in range(1, N):
      xi, yi = xy[order[i]][0], xy[order[i]][1]
      xj, yj = xy[order[i-1]][0], xy[order[i-1]][1]
      sum_ += math.sqrt((xi-xj)**2 + (yi-yj)**2)

  print(sum_ / math.factorial(N))


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
import math

n = int(input())
x = []
y = []
for i in range(n):
  a,b = map(int,input().split())
  x.append(a)
  y.append(b)
total = 1
for i in range(1,n+1):
  total*=i
  
length = []
for i in range(n-1):
  for s in range(1,n):
    if i<s:
      length.append(math.sqrt((x[i]-x[s])**2+(y[i]-y[s])**2))

h = (n-1)/len(length)
if n==2:
  print(sum(length))
else:
  print(h*sum(length))

Submission status: Accepted

Solution code:
from itertools import permutations

n = int(input())
x, y = zip(*[list(map(int, input().split())) for i in range(n)])

per_loop = permutations(range(n))
d = 0
cnt = 0
for t in per_loop:
    for i in range(1, n):
        d += ((x[t[i]]-x[t[i-1]])**2 + (y[t[i]]-y[t[i-1]])**2)**(0.5)
    cnt += 1

print(d / cnt)

Submission status: Accepted

Solution code:
import itertools
import math

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

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

Submission status: Accepted

Solution code:
n=int(input())
xy=[]
for i in range(n):
  xy_=list(map(int,input().split()))
  xy.append(xy_)
  
from itertools import permutations
import math
s=list(permutations(range(n)))
ans=0
for i in s:
  sum_r=0
  for j in range(n-1):
    r=math.sqrt((xy[i[j+1]][0]-xy[i[j]][0])**2+(xy[i[j+1]][1]-xy[i[j]][1])**2)
    sum_r+=r
    
  ans+=sum_r
  
  
print(ans/len(s))

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())                    #n = 町の個数
l = [list(map(int,input().split())) for i in range(n)]
x,y = [list(i) for i in zip(*l)]    #x,y = 町の座標
l = list(range(n))                  
z = list(itertools.permutations(l)) #z = 経路の組み合わせ
m = math.factorial(n)               #m = 経路の個数
t = 0                               #t = 長さの合計

for i in range(m):
    for j in range(n - 1):
        t += math.sqrt((x[z[i][j]] - x[z[i][j+1]]) ** 2 + (y[z[i][j]] - y[z[i][j+1]]) ** 2)

print(t / m)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

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

total = 0
for pattern in permutations(xy):
    dis = 0
    for j in range(n - 1):
        dis += sqrt((pattern[j][0] - pattern[j + 1][0]) ** 2 + (pattern[j][1] - pattern[j + 1][1]) ** 2)
    total += dis

ans = total / len(list(permutations(xy)))
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
XY = [tuple(map(int, input().split())) for _ in range(N)]
cnt = 0
tot = 0
for ptn in itertools.permutations(XY):
    now = ptn[0]
    cnt += 1
    for nex in ptn[1:]:
        tot += math.sqrt(pow(now[0]-nex[0], 2)+pow(now[1]-nex[1], 2))
        now = nex
print(tot/cnt)