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:
from itertools import permutations
import math

N = int(input())
A = [(0, 0) for x in range(N)]

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

pA = permutations(A)

route_count = 0
sum_route_length = 0
for route in pA:
    route_count += 1
    for i in range(1, len(route)):
        distance = math.sqrt(pow(route[i-1][0] - route[i][0], 2) + pow(route[i-1][1] - route[i][1], 2))
        sum_route_length += distance

average = sum_route_length / route_count

print(average)

Submission status: Accepted

Solution code:
import itertools

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

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

sum_distance = 0
cnt = 0

for city in permutations_city_number:
    memo = 0
    for x in city:
        if memo == 0:
            city1 = x
            memo = 1
        sum_distance += ((city_distance[city1][0] - city_distance[x][0]) ** 2 + (city_distance[city1][1] - city_distance[x][1]) ** 2) ** 0.5
    cnt += 1

print(sum_distance/cnt)

Submission status: Accepted

Solution code:
n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
def dfs(v, cost, xy):
  if len(v)==0:
    return cost
  x1, y1 = xy
  res = 0
  for i, v_ in enumerate(v):
    x2, y2 = v_
    res += dfs(v[:i]+v[i+1:], cost+((x1-x2)**2 + (y1-y2)**2)**0.5, v_)
  return res

res = 0
p = 1
for i, xy_ in enumerate(xy):
  res += dfs(xy[:i]+xy[i+1:], 0, xy_)
  p *= (i+1)
print(res/p)

Submission status: Accepted

Solution code:
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
XY = np.array([lr() for _ in range(N)])
X = XY[:, 0]; Y = XY[:, 1]
diff_X = X[:, None] - X[None, :]
diff_Y = Y[:, None] - Y[None, :]
path = (diff_X ** 2 + diff_Y ** 2) ** .5
answer = path.sum() / N
print(answer)

Submission status: Accepted

Solution code:
import sys
import math

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, sys.stdin.readline().split())
    X.append(x)
    Y.append(y)
    
sum = 0

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

ans = sum / (N / 2)

print(ans)

Submission status: Accepted

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

total=0
for i in range(N-1):
  for j in range(i+1,N):
    total+=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5

n=2/N
ans=total*n
print(ans)

Submission status: Accepted

Solution code:
import sys
import math

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
answer = 0
# iとjの距離は(2/N)回足される
XY = [lr() for _ in range(N)]
for i in range(N):
    for j in range(i+1, N):
        x1, y1 = XY[i]
        x2, y2 = XY[j]
        length = ((x1-x2) ** 2 + (y1-y2) ** 2) ** .5
        answer += length

answer *= 2 / N
print(answer)

Submission status: Accepted

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

ans=0
for x1,y1 in xy:
    for x2,y2 in xy:
        ans+=((x2-x1)**2+(y2-y1)**2)**0.5 

print(ans/n)

Submission status: Accepted

Solution code:
#ABC145.C
N = int(input())
x = []
c=0
for i in range(N):
    x1=[int(i) for i in input().split()]
    x.append(x1)
for i in range(N):
    for m in range(N):
        if i!=m:
            c+=((x[i][0]-x[m][0])**2+(x[i][1]-x[m][1])**2)**0.5
print(c/N)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
xy = []
def kaijou(n):
    if n > 1:
        return n*(kaijou(n-1))
    else:
        return 1
for i in range(n):
    tmp = list(map(int,input().split()))
    xy.append(tmp)
ans = 0
num = 0
for i in range(len(xy)):
    for j in range(i+1,len(xy)):
        ans += np.sqrt((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)
        
print(ans*kaijou(n-1)*2/kaijou(n))

Submission status: Accepted

Solution code:
from itertools import permutations as perm
import math

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

for root in list(perm(range(N))):
    for i in range(1, N):
        ans += math.sqrt((coo[root[i]][0]-coo[root[i-1]][0])**2+(coo[root[i]][1]-coo[root[i-1]][1])**2)

print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import math;n = int(input());l = [list(map(int,input().split())) for i in range(n)];dist = 0
for x1,y1 in l:
  for x2,y2 in l:dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(dist/n)

Submission status: Accepted

Solution code:
n = int(input())
zahyou = []
for i in range(n):
    a = input().split()
    zahyou.append(a)
import math


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

allen = 0
for i in zahyou:
    for j in zahyou:
        allen += distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))

ans = float(allen/n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
c=[[] for i in range(n)]
for i in range(n):
  a,b=map(int,input().split())
  c[i].append(a)
  c[i].append(b)

import math
sum=0  
for j in range(n):
  q=c[j][0];w=c[j][1]
  for k in range(j):
    sum+=math.sqrt((c[k][0]-q)**2+(c[k][1]-w)**2)
    
print(float(sum*2/n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from itertools import permutations, combinations,combinations_with_replacement,product
n = int(input())
p = [[0,0] for i in range(n)]
a = [i for i in range(n)]
a = list(permutations(a))
ans = 0
kai = math.factorial(n)

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

for i in range(kai):
    for j in range(n-1):
        ans += ((p[a[i][j]][0]-p[a[i][j+1]][0])**2+(p[a[i][j]][1]-p[a[i][j+1]][1])**2)**0.5

print(ans/kai)

Submission status: Accepted

Solution code:
import math
def distance(x1,x2,y1,y2):
  d=math.sqrt((x1-x2)**2+(y1-y2)**2)
  return d
count=int(input())
zahyou=[]
for i in range(count):
  a=input().split(" ")
  zahyou.append(a)

lenth=0
for i in zahyou:
  for j in zahyou:
    lenth=lenth+distance(int(i[0]),int(j[0]),int(i[1]),int(j[1]))
print(lenth/count)

Submission status: Accepted

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

import itertools


def calc_dist(p1, p2):
    x_delta = p1[0] - p2[0]
    y_delta = p1[1] - p2[1]
    return (x_delta ** 2 + y_delta ** 2) ** (1/2)


if __name__ == "__main__":
    N = int(input())
    A = []
    for _ in range(N):
        x, y = map(int, input().split())
        A.append((x, y))

    dist_list = []
    for permutated in itertools.permutations(A):
        dist = 0
        for i in range(1, len(permutated)):
            dist += calc_dist(permutated[i], permutated[i-1])
        dist_list.append(dist)

    print(sum(dist_list) / len(dist_list))

Submission status: Accepted

Solution code:
from itertools import permutations

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

dist = [[0] * N for _ in range(N)]
for i in range(N):
    for j in range(N):
        dist[i][j] = ((X[i][0] - X[j][0]) ** 2
                      + (X[i][1] - X[j][1]) ** 2) ** 0.5

ans = []
for v in permutations(range(N), N):
    tmp = 0
    for i in range(N - 1):
        tmp += dist[v[i]][v[i + 1]]
    ans.append(tmp)

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

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
x,y = [0]*n,[0]*n
for i in range(n):
  x[i],y[i] = map(int,input().split())
lis = [x for x in range(n)]
permutation_lis = itertools.permutations(lis)
ans = 0
div = math.factorial(n)
def eucleid_dist(a,b):
  return  math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
for path in permutation_lis:
  dist = 0
  for i in range(n-1):
    a = (x[path[i+1]],y[path[i+1]])
    b = (x[path[i]],y[path[i]])
    dist += eucleid_dist(a,b)
  ans += dist/div
print(ans)

Submission status: Accepted

Solution code:
from math import fsum, sqrt
from itertools import permutations
N = int(input())
towns = [tuple(map(int, input().split())) for _ in range(N)]
distances = []
num = 0
for rt in permutations(range(N), N):
    num += 1
    for i in range(1, N):
        x1, y1 = towns[rt[i-1]]
        x2, y2 = towns[rt[i]]
        distance = sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)
        distances.append(distance)
print(fsum(distances) / num)

Submission status: Accepted

Solution code:
from itertools import permutations

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

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

perm = permutations(range(N), N)
d_list = []
for p in perm:
    d = 0
    for i in range(N - 1):
        d += calc_distance(P[p[i]], P[p[i+1]])
    d_list.append(d)
print(sum(d_list) / len(d_list))

Submission status: Accepted

Solution code:
import math

def main():

    N = int(input())

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

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

            dx = x2 - x1
            dy = y2 - y1
            distSq = dx * dx + dy * dy

            total += math.sqrt(distSq)

    print(total * 2 / N)


main()

Submission status: Accepted

Solution code:
import decimal
import math
from itertools import permutations

decimal.getcontext().prec = 16

cache = {}


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


N = int(input())

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

total = 0
count = 0
for points in permutations(P, len(P)):
  it = iter(points)
  last = next(it)
  for p in it:
    total += distance(p, last)
    last = p
  count += 1

print(total / count)

Submission status: Accepted

Solution code:
import itertools

n = int(input())
towns = [tuple(map(int, input().split())) for _ in range(n)]
routes = list(itertools.permutations(towns))


def gen(routes):
    for v in routes:
        for i,  move in enumerate(v):
            if i < n-1:
                d = ((v[i][0] - v[i + 1][0]) ** 2 +
                     (v[i][1] - v[i + 1][1]) ** 2) ** 0.5
                yield d


print(sum(gen(routes)) / len(routes))

Submission status: Accepted

Solution code:
from itertools import permutations

def calc(x, y):
    return ((x[0] - y[0])**2 + (x[1] - y[1])**2)**0.5

def main():
    n = int(input())
    A = [list(map(int, input().split())) for i in range(n)]
    A = list(permutations(A))
    ls = []
    for c in A:
        l = calc(c[0], c[1])
        if len(c) > 2:
            prev_idx = 1
            for a in c[2:]:
                l += calc(c[prev_idx], a)
                prev_idx += 1
        ls.append(l)
    print(sum(ls) / len(ls))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
from itertools import combinations, permutations
import math

N = int(input())
t = np.zeros((N, 2))
for _ in range(N):
    t[_] = np.array(list(map(int, input().split())))

def distance(i, j):
    return np.sqrt(np.sum((t[i] - t[j])**2))

dm = np.zeros((N,N))

for i, j in combinations(range(N), 2):
    dm[i, j] = distance(i, j)

total = 0
for r in permutations(range(N), N):
    r = list(r)
    for i, j in zip(r[:-1], r[1:]):
        total += dm[min(i,j),max(i,j)]
    
res = total / math.factorial(N)
print(res)

Submission status: Accepted

Solution code:
import itertools
import math
N=int(input())
lst=[None]*N
for i in range(N):
    lst[i]=tuple(map(int, input().split()))
total=0
for i in range(N-1):
    for j in range(i+1,N):
        total+=math.sqrt( (lst[i][0]-lst[j][0])**2 + (lst[i][1]-lst[j][1])**2 )

ave=total*2/N
print(ave)

Submission status: Accepted

Solution code:
import numpy as np
import math

N = int(input())

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

gokei = 0
for i in range(N):
    for j in range(i+1, N):
        gokei += np.linalg.norm(X[i]-X[j])

print(gokei*math.factorial(N-1)*2/math.factorial(N))

Submission status: Accepted

Solution code:
import math
import itertools as its
x=int(input())
y=[[float(i) for i in input().split()] for _ in range(x)]
l=0
def di(i1,i2):
  return math.sqrt((y[i1][0]-y[i2][0])**2+(y[i1][1]-y[i2][1])**2)
z=[[di(j,-i-1) for i in range(x-1-j)]for j in range(x)]
yit=list(its.permutations(range(x)))
for i in yit:
  now=0
  while now<x-1:
    if i[now]<i[now+1]:
      l+=z[i[now]][-i[now+1]+i[now]]
    else:
      l+=z[i[now+1]][+i[now+1]-i[now]]
    now+=1
print(l/(len(yit)))

Submission status: Accepted

Solution code:
from math import sqrt

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

Submission status: Accepted

Solution code:
import itertools

n = int(input())
a = [i for i in range(n)]
x,y = [0]*n , [0]*n
for i in range(n):
    x[i],y[i] = map(int,input().split())
r = list(itertools.permutations(a,len(a)))

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

Submission status: Accepted

Solution code:
import itertools
import math

n=int(input())
lis=[i for i in range(n)]
P_lis=itertools.permutations(lis)

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

ans=0
P=list(P_lis)
for i in range(len(P)):
  for j in range(n-1):
    ans+=math.sqrt((x[P[i][j]]-x[P[i][j+1]])**2+(y[P[i][j]]-y[P[i][j+1]])**2)
print(ans/len(P))

Submission status: Accepted

Solution code:
import math

n=int(input())
P=[]
for i in range(n):
    x,y=map(int,input().split())
    P.append([x,y])
    
ans=0
for i in range(n-1):
    x1=P[i][0]
    y1=P[i][1]
    for j in range(i+1,n):
        x2=P[j][0]
        y2=P[j][1]
        ans+=math.sqrt((x1-x2)**2+(y1-y2)**2)
ans=ans*2/n
print(ans)

Submission status: Accepted

Solution code:
import math

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

total = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        x1, y1 = tmp[i]
        x2, y2 = tmp[j]
        total += math.sqrt((x1-x2)**2 + (y1-y2)**2)

print(total * (n - 1) * 2 / (n * (n - 1)))

Submission status: Accepted

Solution code:
import math
N = int(input())
P = [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 += math.sqrt((P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2)

ans *= 2/N
print(ans)

Submission status: Accepted

Solution code:
import math
n = int(input())
x = [0] * n
y = [0] * n
seq = []
for i in range(n):
    x[i],y[i] = map(int,input().split())
    seq.append(i)
import itertools
sum = 0
seq_list = list(itertools.permutations(seq))
for i in range(len(seq_list)):
    for j in range(n-1):
        sum += math.sqrt((x[seq_list[i][j+1]]-x[seq_list[i][j]])**2 + (y[seq_list[i][j+1]]-y[seq_list[i][j]])**2 )

print(sum/len(seq_list))

Submission status: Accepted

Solution code:

import itertools
import math

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

M = 0

for l in itertools.permutations(range(N)):
    L = 0
    for m in range(1, N):
        L += ((X[l[m]][0] - X[l[m-1]][0])**2 + (X[l[m]][1] - X[l[m-1]][1])**2)**0.5
    M += L

print(M / math.factorial(N))

Submission status: Accepted

Solution code:
import itertools
import math
n=int(input())
lst=[None]*n
for i in range(n):
    lst[i]=tuple(map(int, input().split()))
total=0
for v in itertools.permutations(lst):
    for i in range(n-1):
        dis=math.sqrt( (v[i][0]-v[i+1][0])**2 + (v[i][1]-v[i+1][1])**2 )
        total+=dis
print(total/math.factorial(n))

Submission status: Accepted

Solution code:
#template
def inputlist(): return [int(j) for j in input().split()]
from collections import Counter
#template
#issueから始める
N = int(input())
x = [0]*N
y = [0]*N
ans = 0
for i in range(N):
    x[i],y[i] = inputlist()
for i in range(N-1):
    for j in range(i+1,N):
        dx = (x[i]-x[j])**2
        dy = (y[i]-y[j])**2
        dl = (dx+dy)**(1/2)
        ans += 2*dl
print(ans/N)

Submission status: Accepted

Solution code:
from itertools import permutations as perm


def inpl():
    return list(map(int, input().split()))


def getCost(p):
    ret = 0
    for i, ni in zip(p, p[1:]):
        x, y = XY[i]
        nx, ny = XY[ni]
        ret += ((nx-x)**2+(ny-y)**2)**0.5
    return ret


N = int(input())
XY = [inpl() for i in range(N)]

ans = sum(getCost(p) for p in perm([i for i in range(N)]))

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

Submission status: Accepted

Solution code:
def inpl():
    return list(map(int, input().split()))


def backtrack(towns, x=0, y=0, v=0, ans=0, flag=True):
    # print(towns)
    if not towns:
        ans += v
        return ans
    t = 0
    for i in range(len(towns)):
        nx, ny = XY[towns[i]]
        if flag:
            tmp = ((nx - x)**2 + (ny - y)**2)**0.5
        else:
            tmp = 0
        t += backtrack(towns[:i]+towns[i+1:], nx, ny, v+tmp, ans)
    return t + ans


N = int(input())
XY = [inpl() for i in range(N)]

ans = backtrack([i for i in range(N)], flag=False)

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

Submission status: Accepted

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

def dis(a,b):
    d=(a[0]-b[0])**2+(a[1]-b[1])**2
    return d**0.5

ans=0
from itertools import combinations
# listから２つ選ぶ組み合わせ
for a,b in combinations(xy, 2):
    ans+=dis(a,b)
print(2*ans/n)

Submission status: Accepted

Solution code:
from itertools import permutations
import math

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

B = []
for i in permutations(A,2):
    B.append(i)
#print(B)

ans = 0
for i in range(len(B)):
    ans += math.sqrt((B[i][0][0] - B[i][1][0])**2 + (B[i][0][1] - B[i][1][1])**2)

print(ans/N)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for x1, y1 in xy:
    for x2, y2 in xy:
        ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(ans/n)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
li = list(itertools.permutations(range(1,n+1)))
a = []
for _ in range(n):
    a.append([int(x) for x in input().split()])
ans = 0
for i in li:
    for j in range(n-1):
        x = a[i[j]-1][0]-a[i[j+1]-1][0]
        y = a[i[j]-1][1]-a[i[j+1]-1][1]
        ans += math.sqrt(x**2+y**2)
x = 1
for i in range(1,n+1):
    x *= i
print(ans/x)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for x1, y1 in xy:
    for x2, y2 in xy:
        ans += math.sqrt((x1-x2)**2 + (y1-y2)**2)
print(ans/n)

Submission status: Accepted

Solution code:
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s

n = load()

p = []
for i in range(n):
    x, y = load_list()
    p.append((x, y))

perms = perm_li([i for i in range(0, n)])

leng = []
for perm in perms:
    l = 0
    for i in range(1, len(perm)):
        e1, e2 = perm[i-1], perm[i]
        x1, y1 = p[e1][0], p[e1][1]
        x2, y2 = p[e2][0], p[e2][1]
        l += math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1, 2))
    leng.append(l)

print(sum(leng) / len(leng))

Submission status: Accepted

Solution code:
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
dist = 0
for x1,y1 in l:
    for x2,y2 in l:
        dist += math.sqrt((x1-x2)**2 + (y1-y2)**2)
ave = dist/n
print(ave)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import permutations

def resolve():
    N=int(input())
    l=[[0,0] for i in range(N)]
    for i in range(N):
        x,y=map(int,input().split())
        l[i][0],l[i][1]=x,y

    p=permutations(l)
    dist = 0
    for v in p:
        for i in range(N-1):
            dist+=((v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2)**0.5

    print(dist/len(list(permutations((l)))))


resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())

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

routes = list(itertools.permutations(lst))

def distance(a, b):
    return (((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)) ** 0.5

routes = [i for i in routes]
distancies = []
for i, r in enumerate(routes):
    for j, a in enumerate(r):
        if j >= len(r) - 1: break
        b = r[j + 1]
        ab_dist = distance(a, b)
        distancies.append(ab_dist)

print(sum(distancies) / len(routes))

Submission status: Accepted

Solution code:
import itertools
from math import factorial

N=int(input())
x=[0]*N
y=[0]*N
path=[0]*(factorial(N))
for i in range(N):
  x[i],y[i] = map(int,input().split())
  
L=list( itertools.permutations([i for i in range(N)]) )
for j,order in enumerate(L):
  for k in range(1,len(order)):
    path[j] += ( (x[order[k]]-x[order[k-1]])**2 + (y[order[k]]-y[order[k-1]])**2 )**0.5
  #print(j,order,path[j])
    
print(sum(path)/len(path))
#  for i,k in enumerate(order):
#    if i==0:
#      pass
#    else:
#      path[j] +=

Submission status: Accepted

Solution code:

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

l = 0

for i in range(n):
    for j in range(n):
        l+=((ad[i][0]-ad[j][0])**2+(ad[i][1]-ad[j][1])**2)**(1/2)

ans = l / n
print(ans)

Submission status: Accepted

Solution code:
n=int(input())
a=[[int(i) for i in input().split()] for i in range(n)]
import itertools as it
import math
pe=list(it.permutations(range(n),n))

total=0
for i in pe:
    for x in range(len(i)-1):
        total+=((a[i[x]][0]-a[i[x+1]][0])**2+(a[i[x]][1]-a[i[x+1]][1])**2)**0.5

print(total/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
mati = list()
for _ in range(N):
    mati.append(list(map(int, input().split())))

mati_list = list(range(N))
comb = list(itertools.combinations(mati_list, 2))
length = list()
for i, k in comb:
    x_i, y_i = mati[i]
    x_k, y_k = mati[k]
    l = ((x_i - x_k) ** 2 + (y_i - y_k) ** 2) ** 0.5
    length.append(l)
ave = sum(length) / len(length)
print(ave*(N-1))

Submission status: Accepted

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

import itertools
#ans = 0
cnt = 0
dis_ = 0
sum_ = 0
for route in itertools.permutations(range(N), N):
    cnt += 1
    #ans = 0
    #print(i)
    #dis = 0
    dis_ = 0
    for i in range(N - 1):
        dis = (xy[route[i]][0] - xy[route[i + 1]][0])**2 + (xy[route[i]][1] - xy[route[i + 1]][1])**2
        dis = dis**0.5
        dis_ += dis
    sum_ += dis_

print(sum_ / cnt)

Submission status: Accepted

Solution code:
from math import sqrt, factorial
from itertools import permutations
N = int(input())
Ts = [list(map(int, input().split())) for _ in range(N)]
points = list(range(N))

ans = 0
for pat in permutations(Ts):
  x = 0
  for i, p in enumerate(pat):
    if i==0:
      past = p
      continue
    a, b = past
    c, d = p
    x += sqrt((a-c)**2+(b-d)**2)
  ans += x

print(ans/factorial(N))

Submission status: Accepted

Solution code:
import itertools

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

def distance(a, b):
  res = (a[0]-b[0])**2 + (a[1]-b[1])**2
  return res ** 0.5
  
ans = 0.0
combs = itertools.combinations(range(N), 2)
for comb in combs:
  ans += distance(xy[comb[0]], xy[comb[1]])

ans = ans * 2 / N
print(ans)

Submission status: Accepted

Solution code:
import itertools

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

def distance(a, b):
  res = (a[0]-b[0])**2 + (a[1]-b[1])**2
  return res ** 0.5
  
ans = 0.0
cnt = 0
perms = itertools.permutations(range(N))
for perm in perms:
  cnt += 1
  for j in range(N-1):
    a = perm[j]
    b = perm[j+1]
    ans += distance(xy[a], xy[b])

ans /= cnt
print(ans)

Submission status: Accepted

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

def dis(a, b, c, d):
    return ((a - c) ** 2 + (b - d) ** 2) ** (1/2)

s = 0
m = 0
for i in range(n):
    for j in range(i+1, n):
        a, b = t[i]
        c, d = t[j]
        s += dis(a, b, c, d)
        m += 1

ans = (s / m * (n-1))
print(ans)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
xy = []
for _ in range(N):
    xy.append(list(map(int,input().split())))
    
alls = list(itertools.permutations(range(1,N+1))) #順列全て
def length(X,Y): #XとYの距離
    l = math.sqrt((X[0]-Y[0])**2 + (X[1]-Y[1])**2)
    return l
Nk = math.factorial(N) #Nの階乗

L = 0
for i in range(Nk):
    l = 0
    for j in range(N-1):
        c1 = xy[alls[i][j]-1]
        c2 = xy[alls[i][j+1]-1]
        l += length(c1,c2)
    L += l
    
print(L/Nk)

Submission status: Accepted

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

dist = 0.0

for i in range(N):
    for j in range(N):
        dist += ((P[i][0] - P[j][0])**2 + (P[i][1] - P[j][1])**2)**0.5

print(dist / N)

Submission status: Accepted

Solution code:
import math
import itertools

A=[]
N = int(input())
E=math.factorial(N)
lis = [x for x in range(0,N)] # 0からN-1までのリスト
P = list(itertools.permutations(lis))# 全ての場合のリストを生成

for i in range(N):
 x=list(map(int,input().split()))
 A.append(x)
B=0
for j in range(E):
 for k in range(N-1):
  a=P[j][k]
  b=P[j][k+1]
  B+=((A[a][0]-A[b][0])**2+(A[a][1]-A[b][1])**2)**(1/2)
C=B/E
print(C)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())

xy = []

for _ in range(n):
    xy.append(tuple(map(int,input().split())))

ans = 0

per = itertools.permutations(range(n))

for p in per:
    x1,y1 = xy[p[0]]
    dif_tmp = 0
    for i in range(1,len(p)):
        x2,y2 = xy[p[i]]
        dif_tmp += ((x1-x2)**2 + (y1-y2)**2)**0.5
        x1,y1 = x2,y2

    ans += dif_tmp

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