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())
s=[list(map(int, input().split())) for i in range(n)]
t=[i for i in range(n)]
x=math.factorial(n)
ans=0
for v in itertools.permutations(s, n):
    for j in range(len(v)-1):
        ans+=(abs(v[j][0]-v[j+1][0])**2+abs(v[j][1]-v[j+1][1])**2)**0.5
        
print(ans/x)

Submission status: Accepted

Solution code:
def dist(A, B):
    return ((A[0]-B[0])**2 + (A[1]-B[1])**2)**(0.5)

from math import factorial
from itertools import permutations
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
dists = 0
for l in permutations(XY):
    for i in range(len(l)-1):
        dists += dist(l[i], l[i+1])

print(dists/factorial(N))

Submission status: Accepted

Solution code:

import sys
import heapq
import math
import itertools

INF = float("inf")


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


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

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

    ans = 0
    data = [i for i in range(0, N)]
    routes = list(itertools.permutations(data))
    for route in routes:
        # print(route)
        for i in range(0, len(route) - 1):
            # print(x[i], y[i], x[i+1], y[i+1])
            test = dis(x[route[i]], y[route[i]], x[route[i+1]], y[route[i+1]])
            # print(test)
            ans += test

    print(ans / len(routes))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np
import itertools

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

def dist(a,b):
  return ((a[0]-b[0])**2+(a[1]-b[1])**2)**(1/2)
  
a=[]
for i in range(n):
  b=[]
  for j in range(n):
      b.append(dist(s[i],s[j]))
  a.append(b)

t=np.arange(n)      

sum=0
k=0
for v in itertools.permutations(t, n):
  k+=1
  for m in range(n-1):
    sum += a[v[m]][v[m+1]]

print(sum/k)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def kaijo(n):
    if n == 1:
        return n
    return n * kaijo(n-1)

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

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

    print(tmp*2/n)



    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

N = int(input())
xy = []
for _ in range(N):
  xy.append(list(map(int, input().split())))
  
xy = np.array(xy)
d = np.linalg.norm(xy[np.newaxis,:,:] - xy[:,np.newaxis,:], axis=2)

print(np.sum(d)/N)

Submission status: Accepted

Solution code:
N=int(input())

A=[[0,0] for i in range(N)]
B=[0]*(N*(N-1)//2)
for i in range(N):
    A[i][0],A[i][1]=map(int,input().split())
c=0
for i in range(N):
    for j in range(i+1,N):
        B[c]=((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)**0.5
        c+=1

D=(N)*(N-1)/2

print(sum(B)*(N-1)/(D))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n=int(input())
x=[0]*n
y=[0]*n
cnt=1
for l in range(1,n+1):
    cnt*=l
for i in range(n):
    x[i],y[i]=map(int,input().split())
    ###
ans=0
for j in range(n):
    for k in range(n):
        ans+=((((x[j]-x[k])**2)+((y[j]-y[k])**2))**(1/2))
ans/=2
ans*=(cnt//n)*2
print(ans/cnt)

Submission status: Accepted

Solution code:
import itertools
import math

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

ave = 0
patterns = list(itertools.permutations(towns))
for path in patterns:
    distance = 0
    for i in range(1, len(path)):
        diff_x = path[i][0] - path[i-1][0]
        diff_y = path[i][1] - path[i-1][1]
        distance += math.sqrt(diff_x ** 2 + diff_y ** 2)
    ave += distance
print(ave / len(patterns))

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
input_list = [input() for i in range(N)]
count = 0
sum_length = 0

for points in itertools.permutations(input_list, N):
    length = 0
    for i in range(N-1):
        x, y = map(int, points[i].split())
        next_x, next_y = map(int, points[i + 1].split())
        length += math.sqrt((next_x - x) ** 2 + (next_y - y) ** 2)
    sum_length += length
    count += 1

print(sum_length/count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations
import math


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

lst = list(range(N)) 
distance = 0

for root in permutations(lst):
    for i in range(N-1):
        distance += math.sqrt((xy[root[i]][0]-xy[root[i+1]][0])**2
                              + (xy[root[i]][1] -xy[root[i+1]][1])**2)
distance /= math.factorial(N)
print(distance)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

import math

N = int(input().strip())
pos_list = []

for _ in range(N):
    obj = input().strip().split(' ')
    x = float(obj[0])
    y = float(obj[1])
    pos_list.append((x, y))

total = 0
for i in range(N):
    xi, yi = pos_list[i]
    for j in range(i + 1, N):
        xj, yj = pos_list[j]
        dist = math.sqrt((xi - xj) ** 2 + (yi - yj) ** 2)
        total += dist

res = total * 2 / N
print(res)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = [0]*n
y = [0]*n
s = 1
for i in range(n):
    x[i], y[i] = map(int, input().split())
    s *= (i+1)
l = 0
for i in range(n):
    for j in range(n):
        if i > j:
            l += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
s2 = s//n

print(l*s2*2/s)

Submission status: Accepted

Solution code:
from itertools import permutations


N = int(input())

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

routes = list(permutations(range(N)))

tmp = 0
cnt = 0
for route in routes:
    for i in range(1, N):
        FROM = route[i-1]
        TO = route[i]
        tmp += ((XY[FROM][0]-XY[TO][0])**2 + (XY[FROM][1]-XY[TO][1])**2)**0.5
    cnt+=1

print(tmp/cnt)

Submission status: Accepted

Solution code:
n = int(input())
X, Y= [0]*n,[0]*n

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

def kaijo(x):
    if x==1:
        return 1
    else:
        return x*kaijo(x-1)

dis = 0.0
for i in range(n):
    for j in range(n):
        dis += (((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)*kaijo(n-1)


print(dis/kaijo(n))

Submission status: Accepted

Solution code:
import math
import itertools

n = int(input())

p = []
for i in range(n):
    x, y = map(int, input().split())
    p.append((x, y))
    
def dist(p1, p2):
    return math.sqrt(math.pow(p1[0]-p2[0], 2) + math.pow(p1[1]-p2[1], 2))
    
patterns = list(itertools.permutations(list(range(n))))


total = 0
for pattern in patterns:
    for i in range(n):
        if i+1 == n:
            continue
        total += dist(p[pattern[i]], p[pattern[i+1]])
        
print(total/len(patterns))

Submission status: Accepted

Solution code:
N = int(input())
s = []
for i in range(N):
  s.append([int(x) for x in input().split()])
import math
num = math.factorial(N)
n = N-1
p = sum(range(N))
a = num * n//p
#print(a)

d = 0
for i in range(len(s)-1):
  t = s[i]
  for j in range(i+1,len(s)):
    k = s[j]
    d += math.sqrt((t[0]-k[0])**2+(t[1]-k[1])**2)
print(a*d/num)

Submission status: Accepted

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


ans=0
P=list(itertools.permutations([i for i in range(n)]))
for p in P:
  for i in range(1,len(p)):
    xi,xj=XY[p[i-1]][0],XY[p[i]][0]
    yi,yj=XY[p[i-1]][1],XY[p[i]][1]
    ans+=math.sqrt((xi-xj)**2 + (yi-yj)**2)
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import sys
import math
import itertools

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def pp(n):
    c = 1
    for i in range(1, n+1):
        c *= i
    return c


def solve(inputs):
    towns = list(map(string_to_int, inputs))

    distances = []
    sum_distance = 0
    for t in towns:
        ds = []
        for t2 in towns:
            d = math.sqrt((t[0] - t2[0]) ** 2 + (t[1] - t2[1]) ** 2)
            ds.append(d)
            sum_distance += d
        distances.append(ds)

    per = list(itertools.permutations(range(0, len(towns))))
    sum_d = 0
    count = 0
    for p in per:
        d = 0
        for i, index in enumerate(p):
            if i == len(towns) - 1:
                break
            d += distances[index][p[i+1]]
        sum_d += d
        count += 1
    return sum_d / count


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    ret = solve(inputs(N))
    print(ret)

Submission status: Accepted

Solution code:
import math


def main():
    N = int(input())
    x = []
    y = []
    total = 0
    
    for i in range(N):
        a, b = map(int, input().split())
        x.append(a)
        y.append(b)
    for i in range(N):
        now_x = x[i]
        now_y = y[i]
        for j in range(N):
            if i == j:
                continue
            total += math.sqrt(abs(now_x - x[j]) ** 2 + abs(now_y - y[j]) ** 2) * math.factorial(N - 1)
    print("{0:.7f}".format(total / math.factorial(N)))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math

N = int(input())
l = []
for i in range(N):
  l.append([int(x) for x in input().split()])
sum = 0
for i in range(N-1):
  for j in range(i+1, N):
    sum += math.sqrt((l[i][0] - l[j][0]) ** 2 + (l[i][1] - l[j][1])** 2)
ans = sum / N * 2
print(ans)

Submission status: Accepted

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

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())

sum = 0
M = math.factorial(N-1)
for i in range(N):
    for j in range(N):
           sum += math.sqrt((x[j]-x[i])*(x[j]-x[i]) + (y[j]-y[i])*(y[j]-y[i])) * M


print(sum/math.factorial(N))

Submission status: Accepted

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

f = math.factorial(N)
a = N * (N - 1) // 2


sumd = 0
for n in range(N - 1):
    for m in range(n, N):
        sumd += ((XY[n][0] - XY[m][0]) ** 2 + (XY[n][1] - XY[m][1]) ** 2) ** 0.5

print (sumd   / N * 2)

Submission status: Accepted

Solution code:
import numpy as np
import math

N = int(input())
ave = []
ans = 0.0

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

for i in range(N):
    Sum = 0
    for j in range(N):
        if(i == j):
            continue
        else:
            Sum += math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)

    ans += (Sum / float(N))

print(ans)

Submission status: Accepted

Solution code:
import itertools
import math


def find_path_len(p, distances):
    dist = 0
    for i in range(1, n):
        dist += distances[p[i]][p[i-1]]
    return dist


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

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

distances = [[0 for _ in range(n)] for _ in range(n)]

for i in range(n):
    for j in range(n):
        s = a[i]
        f = a[j]
        d = math.sqrt((s[0] - f[0]) ** 2 + (s[1] - f[1]) ** 2)
        distances[i][j] = d
        distances[j][i] = d

pathes_length = list(map(lambda x: find_path_len(x, distances), pathes))

print(sum(pathes_length) / len(pathes_length))

Submission status: Accepted

Solution code:
n = int(input())
x, y = [None]*n, [None]*n

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


def dist(i, j):
    return ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5


total = 0
for i in range(n-1):
    for j in range(i+1, n):
        total += dist(i, j)

print(2*total/n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())
town = [0]*N

for i in range(N):
    town[i] = [int(i) for i in input().split()]
    
k = math.factorial(N)

zenbu = list(itertools.permutations(town))

kyori = 0

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

print(kyori/k)

Submission status: Accepted

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

pair = math.factorial(n) // math.factorial(n-2)
avg = 0
for x1, y1 in place:
  for x2, y2 in place:
    avg += math.sqrt((x1-x2)**2 + (y1-y2)**2)
avg = avg / pair

result = avg * (n - 1)
print(result)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from math import factorial
from itertools import permutations

def solve():
    N = int(input())
    Z = np.zeros((N,1,2))
    for i in range(N):
        x, y = map(int, input().split())
        Z[i] = x,y
    W = Z.swapaxes(0,1)
    return str(np.sqrt(((Z-W)**2).sum(axis=-1)).sum()*factorial(N-1)/factorial(N))

if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
import math
from itertools import permutations


def length(p, q):
    return math.sqrt((p[0] - q[0]) ** 2 + (p[1] - q[1]) ** 2)


n = int(input())
l = [list(map(int, input().split(" "))) for i in range(n)]
orders = list(permutations([i for i in range(n)]))

allL = 0

for i in range(len(orders)):
    order = orders[i]
    d = [length(l[order[j]], l[order[j + 1]]) for j in range(n - 1)]
    allL += sum(d)

print(allL / len(orders))

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from itertools import permutations

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    XY = [LIST() for _ in range(N)]

    pmt = list(permutations(range(N)))

    dist = 0
    for p in pmt:
        for cur, nxt in zip(p[:N-1], p[1:]):
            dist += sqrt((XY[nxt][0] - XY[cur][0])**2 + (XY[nxt][1] - XY[cur][1])**2)

    print(dist/len(pmt))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import math
import bisect
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


# A
def A():
    r = I()
    print(r * r)
    return


# B
def B():
    N = I()
    s = S()
    if N % 2 != 0:
        print("No")
    elif ''.join(s[:N // 2]) == ''.join(s[N // 2:]):
        print("Yes")
    else:
        print("No")
    return


# C
def C():
    n = I()
    a = [LI() for i in range(n)]
    ans = 0
    for i in range(n):
        for j in range(i + 1, n):
            ans += pow(pow(a[i][0] - a[j][0], 2) + pow(a[i][1] - a[j][1], 2), 0.5)
    avg = ans / (n*(n-1)/2)
    print(avg * (n - 1))
    return


# D
def D():
    return


# E
def E():
    return


# F
def F():
    return


# Unittest
def resolve():
    C()
    return


# Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
import itertools

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

kyori = 0
num = 0
for v in itertools.permutations(Town, N):
    num += 1
    for i in range(N-1):
        kyori += ((v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2)**0.5

print(kyori/num)

Submission status: Accepted

Solution code:
import sys
import itertools
import math
n = int(sys.stdin.readline())

pos = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]
a = list(itertools.permutations(pos, n))
#print(pos)
ans = 0
for ele in a:
    #print(ele)
    for i in range(n-1):
        ans += math.sqrt((ele[i][0] - ele[i+1][0])**2 + (ele[i][1] - ele[i+1][1])**2)
print(ans/len(a))

Submission status: Accepted

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

N, *XY = map(int, open(0).read().split())

XY = list(zip(*[iter(XY)] * 2))
ans = 0
for p in permutations(XY):
    ans += sum(hypot(ax - bx, ay - by) for (ax, ay), (bx, by) in zip(p, p[1:]))

print("{:.9f}".format(ans / factorial(N)))

Submission status: Accepted

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

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

makepath(0, -1)

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

Submission status: Accepted

Solution code:
import math

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

dist = [[0] * N for _ in range(N)]


def pow(n):
    if n == 1:
        return 1
    else:
        return n * pow(n - 1)

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


sum_ = 0
p = pow(N - 1)
for i in range(N):
    for j in range(i, N):
        c = d(pos[i][0], pos[i][1], pos[j][0], pos[j][1])
        sum_ += c * p * 2

print(sum_ / pow(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())
sum=0
for i in range(n-1):
  for j in range(i+1,n):
    sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(2*sum/n)

Submission status: Accepted

Solution code:
import sys
from itertools import permutations

input = sys.stdin.readline
def main():
    N = int(input())
    x, y = [], []
    
    for i in range(N):
        a, b = map(int, input().split())
        x.append(a)
        y.append(b)
        
    table = {}
    
    for i in range(N):
        for j in range(N):
            if i == j: continue
            
            table[(i, j)] = ((x[i]-x[j]) ** 2 + (y[i]-y[j]) ** 2) ** 0.5
            
    ans = 0
    
    for r in list(permutations([i for i in range(N)])):  
        for j in range(N-1):
            ans += table[(r[j], r[j+1])]
    
    cur = 1
    for i in range(1, N+1): cur *= i
        
    print(ans / cur)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
def combination(x,y):
    return math.factorial(x)//(math.factorial(y)*math.factorial(x-y))

n = int(input())
xs = []
ys = []
sum = 0
for i in range(n):
    [x,y] = [int(i) for i in input().split()]
    xs.append(x)
    ys.append(y)
for i in range(n):
    for j in range(i+1, n):
        sum += math.sqrt((xs[i]-xs[j])**2 +(ys[i] - ys[j])**2)
if n > 2:
    sum *= math.factorial(n-1)*2
else:
    sum *= 2
print(sum/math.factorial(n))

Submission status: Accepted

Solution code:
import math
n = int(input())
A = []
for i in range(n):
  a,b = map(int,input().split())
  A.append([a,b])
sum = 0
for i in range(n):
  for j in range(n):
    if j <= i:
      continue
    else:
      sum += math.sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)

print(sum*2/n)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
x = list() 
y = list()
for i in range(n):
    a,b = map(int, input().split())
    x.append(a)
    y.append(b)
its = list()
for val in range(n):
    its.append(val)
it = list(itertools.permutations(its))
all = 0
for i in it:
    for j in range(1, len(i)):
        c = math.sqrt((x[i[j-1]]-x[i[j]])**2 + (y[i[j-1]]-y[i[j]])**2)
        all += c
all /= len(it)
print(all)

Submission status: Accepted

Solution code:
from itertools import permutations
import math

n = int(input())
xy = [[int(i) for i in input().split()] for i in range(n)]
d = 0

for p in permutations(range(n)):

    p = list(p)
    sum = 0
    for i in range(n-1):
        xi,yi = xy[p[i]]
        xj,yj = xy[p[i+1]]
        sum += math.sqrt((xi-xj)**2 + (yi-yj)**2)
    d += sum

print(d/math.factorial(n))

Submission status: Accepted

Solution code:
n = int(input())
X = []
for _ in range(n):
    x, y = map(int, input().split())
    X += [(x, y)]

from itertools import permutations
import math

def calc_distance(z_list):
    dist = 0
    (_x, _y) = z_list[0]
    for _x2, _y2 in z_list[1:]:
        dist += math.sqrt(abs(_x-_x2)**2+abs(_y-_y2)**2)
        _x = _x2
        _y = _y2
    return dist

ans = 0
for z in permutations(X):
    ans += calc_distance(z)

print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import math

n=int(input())
city=[[int(i) for i in input().split()] for i in range(n)]
nkai=math.factorial(n)
n1kai=math.factorial(n-1)

lengths=[]
for i in range(n):
  for j in range(n):
    length=((city[i][0]-city[j][0])**2+(city[i][1]-city[j][1])**2)**0.5
    lengths.append(length)
   
total=n1kai*2*sum(lengths)
ans=total/nkai/2
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
towns = []
for i in range(n):
  towns.append([int(x) for x in input().split()])
#print(towns)

patterns = list(itertools.permutations(towns, n))

answers = []
for pattern in patterns:
  distance = 0
  for i in range(n-1):
    distance += math.sqrt((pattern[i+1][0] - pattern[i][0])**2+(pattern[i+1][1] - pattern[i][1])**2)
  answers.append(distance)

#print(answers)
print(sum(answers)/len(answers))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt
def dist(x1,y1,x2,y2):
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
n = int(input().strip())
pl=[]
for i in range(n):
    pl.append(i)
l=[]
for i in range(n):
    x,y=map(int,input().strip().split())
    l.append([x,y])
d=[]
for i in permutations(pl):
    x=list(i)
    s=0
    for i in range(n-1):
        s+=dist(l[x[i]][0],l[x[i]][1],l[x[i+1]][0],l[x[i+1]][1])
    d.append(s)
avg=0.0
for i in range(len(d)):
    avg+=d[i]
print(avg/len(d))

Submission status: Accepted

Solution code:
import subprocess
import os
import time


import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    n = int(input())
    coordinates = []

    for i in range(n):
        coordinates.append(list(map(int, input().split())))

    count = 0

    for x in range(n):
        for y in range(x+1, n):
            xg = (coordinates[x][0] - coordinates[y][0])**2
            yg = (coordinates[x][1] - coordinates[y][1])**2
            count += math.sqrt(xg+yg)

    r_avg = count / (n**2/2)

    print(r_avg * n)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

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

total = 0
for keiro in list(it.permutations(point)):
  for i, town in enumerate(keiro[:-1]):
    x1, y1 = keiro[i]
    x2, y2 = keiro[i+1]
    total += math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
  
print(total/len(list(it.permutations(point))))

Submission status: Accepted

Solution code:
from itertools import permutations

def dist(xy1, xy2):
  return ((xy1[0] - xy2[0]) ** 2 + (xy1[1] - xy2[1]) ** 2)**.5

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

distSum = 0
for line in li:
  for i in range(N-1):
    distSum += dist(XY[line[i]], XY[line[i+1]])
  
print(distSum / lenli)

Submission status: Accepted

Solution code:
N = int(input())
XY = []
for _ in range(N):
    XY.append([int(i) for i in input().split()])
case_list = [n for n in range(N)]
from itertools import permutations
P = list(permutations(case_list,N))
dist_sum = 0
cnt = 0
for p in P:
    dist = 0
    for i in range(len(p)-1):
        dist += ((XY[p[i+1]][0] - XY[p[i]][0]) ** 2 + (XY[p[i+1]][1] - XY[p[i]][1]) ** 2) ** 0.5
    dist_sum += dist
    cnt += 1
print(dist_sum / cnt)

Submission status: Accepted

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


def length(point1, point2):
    delx = point1[0]-point2[0]
    dely = point1[1]-point2[1]
    return math.pow(delx*delx + dely*dely, 0.5)


def main():
    count = 0
    ways = math.factorial(n)
    for route in itertools.permutations(point_range, n):
        for i in range(len(route)-1):
          count += length(points[route[i]], points[route[i+1]])

    print(count / ways)

main()

Submission status: Accepted

Solution code:
import math


def get_input():

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


def distance(p1, p2):

    d = (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2
    return math.sqrt(d)


def main():

    N, cities = get_input()
    dist = 0
    for i in range(N):
        for j in range(i+1, N):
            start = cities[i]
            goal = cities[j]
            dist += distance(start, goal) * 2

    print(dist / N)


main()

Submission status: Accepted

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




N = int(input())

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

L = 0
for i, j in list(itertools.combinations([i for i in range(N)], 2)):
    x, y = town[i]
    z, w = town[j]
    L += sqrt((x - z)**2 + (y - w)**2)
print(L * 2 / N)

Submission status: Accepted

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

dist = [[math.sqrt((point[i][0] - point[j][0])**2 + (point[i][1] - point[j][1])**2) for j in range(n) ] for i in range(n)]
ans = 0
l = [i for i in range(n)]
for v in itertools.permutations(l):
  ans += sum([dist[v[i]][v[i+1]] for i in range(n-1)])
print(ans / math.factorial(n))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import itertools

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

P=list(itertools.permutations(range(N)))
pattern_num=len(P)


total=0

for L in P:
    l=0    #長さ
    for i,n in enumerate(L):
        if i==0:
            pass
        else:
            x2=xy[n][0]
            y2=xy[n][1]
            x1=xy[prev_n][0]
            y1=xy[prev_n][1]
            l+=( (x2-x1)**2+(y2-y1)**2 )**0.5
        prev_n=n
    total+=l

print total/pattern_num

Submission status: Accepted

Solution code:
from itertools import permutations

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

all = list(permutations(town,n))

#print(all)

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

print(sum/len(all))

Submission status: Accepted

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

Submission status: Accepted

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

seq = [i+1 for i in range(n)]
#print(seq)
p_seq = list(itertools.permutations(seq))
#print(p_seq[0][1])

#距離を求める関数。引数はリストのインデックス
def dis(num1,num2):
  d = ((xy[num1][0]-xy[num2][0])**2 + (xy[num1][1]-xy[num2][1])**2)**0.5
  return d

l = len(p_seq)
ans = 0
for i in range(l):
  for j in range(1,n):
    ans += dis(p_seq[i][j-1]-1,p_seq[i][j]-1)
    
print(ans/l)