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

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

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

sm = 0
for itr in permutations(xy):
    dist = 0
    x, y = itr[0]
    for nx, ny in itr[1: ]:
        dist += ((nx-x)**2 + (ny-y)**2) ** 0.5
        x, y = nx, ny

    sm += dist

print(sm / n_fact)

Submission status: Accepted

Solution code:
from copy import copy
n = int(input())
x, y = [], []
for i in range(n):
    q, p = map(int, input().split())
    x.append(q)
    y.append(p)

x1 = copy(x)
y1 = copy(y)

ans = 0
for i in range(len(x)):
    for j in range(i + 1, len(x)):
        ans += ((x1[i] - x[j]) ** 2 + (y1[i] - y[j]) ** 2) ** (1 / 2)
        
      

print(ans * 2 / n)

Submission status: Accepted

Solution code:
import math
n=int(input())

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

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

#ダブリ p=math.factorial(n-1)*2
ave=sum/n
print(float(ave))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np
import math
import itertools

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

def solve(N: int, x: "List[int]", y: "List[int]"):
    d = 0.0
    for v in itertools.permutations([i for i in range(N)],N):
        for i in range(len(v)-1):
            dist = distance(x[v[i]], y[v[i]],x[v[i+1]], y[v[i+1]])
            d += dist

    print(d/math.factorial(N))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

road = [0]*n
for i in range(n):
    road[i] = i

road_list = list(itertools.permutations(road))


def distance(a, b):
    x_a = xy[a][0]
    y_a = xy[a][1]
    x_b = xy[b][0]
    y_b = xy[b][1]
    dist = ((x_a - x_b)**2 + (y_a - y_b)**2)**0.5
    return dist


ans = 0

for i in range(len(road_list)):
    for j in range(len(road_list[i])-1):
        ans += distance(road_list[i][j+1], road_list[i][j])

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

Submission status: Accepted

Solution code:

#tuple -> float
def dst(point_a, point_b):
    return ((point_a[0]-point_b[0])**2 + (point_a[1]-point_b[1])**2)**(0.5)
   

def main():
    #N!通りの経路を構成しても間に合うので構成する
    n = int(input()) 
    towns = []
    for _ in range(n):
        x, y = map(int, input().split())
        towns.append((x, y))
    cnt = 0 
    s = 0
    from itertools import permutations
    for i in permutations(towns):
        cnt += 1
        for j in range(n-1):
            s += dst(i[j], i[j+1])

    ans = s/cnt
    print(ans)
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
dis = [list(map(int,input().split())) for _ in range(n)]
ans = 0
num = 0
from itertools import permutations
for path in list(permutations(range(n))):
  num += 1
  path = list(path)
  distance = 0
  for i in range(1,n):
    xi = dis[path[i-1]][0]
    xj = dis[path[i]][0]
    yi = dis[path[i-1]][1]
    yj = dis[path[i]][1]
    distance += (pow(xi-xj,2)+pow(yi-yj,2))**0.5
  ans = ans + distance
ans = ans/num
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
xy = []

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

dist = 0

for i in range(n):
    for j in range(n):
        dist += (((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5)/n

print(dist)

Submission status: Accepted

Solution code:
n = int(input())
xy = []

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

dist = 0

for i in range(n):
    for j in range(n):
        if i != j:
            dist += (((xy[i][0] - xy[j][0])**2 + (xy[i][1] - xy[j][1])**2)**0.5)/n

print(dist)

Submission status: Accepted

Solution code:
n = int(input())
xy = []

for _ in range(n):
    xy.append(input().split())

dist = 0

for i in range(n):
    for j in range(n):
        if i != j:
            dist += (((int(xy[i][0]) - int(xy[j][0]))**2 + (int(xy[i][1]) - int(xy[j][1]))**2)**0.5)/n

print(dist)

Submission status: Accepted

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

def distance(point1, point2):
    return sqrt((point1[0]-point2[0])**2 + (point1[1]-point2[1])**2)

ans = 0
per = permutations(xy, n)
persize = factorial(n)
cost = 0
for i in per:
    cpoint = i[0]
    for j in i[1:]:
        cost += distance(cpoint, j)
        cpoint = j
ans = cost/persize
print(ans)

Submission status: Accepted

Solution code:
import math
from itertools import permutations

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

ans = []
for i in permutations(range(n)):
    temp = 0
    for j in range(n-1):
        temp += math.sqrt((l[i[j+1]][0] - l[i[j]][0])**2 + (l[i[j+1]][1] - l[i[j]][1])**2)
    ans.append(temp)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def permutation(index, n): # せっかくなので実装
  if index == 1:
    new_box = []
    for i in range(n):
      new_box.append([i])
    return new_box
  
  curr_box = permutation(index - 1, n)
  new_box = []
  for fact_list in curr_box:
    for i in range(n):
      if i in fact_list:
        continue
      new_box.append(fact_list + [i])
  return new_box

def distance(p1, p2, xy):
  return ((xy[p1][0] - xy[p2][0]) ** 2 + (xy[p1][1] - xy[p2][1]) ** 2) ** (1 / 2)

n = int(input())
xy = [[int(i) for i in input().split()] for _ in range(n)]
per = permutation(n, n)
nway = len(per)
sum_dist = 0
for l in per:
  for i in range(len(l) - 1):
    sum_dist += distance(l[i], l[i + 1], xy)
print(sum_dist / nway)

Submission status: Accepted

Solution code:
import math
import itertools
from functools import lru_cache

N = int(input())

x = [0]*N
y = [0]*N
d = []

@lru_cache(maxsize=1000)
def calc(x1,y1,x2,y2):
        d1 = int((int(x2) - int(x1))** 2)
        d2 = int((int(y2) - int(y1))** 2)
        distance = d1 + d2
        return(math.sqrt(distance))

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

a = list(itertools.permutations(range(N)))

# 順列
for i in range(len(a)):
    b = a[i]
    for j in range(len(b)-1):
            ans = calc(x[b[j]],y[b[j]],x[b[j+1]],y[b[j+1]])
            d.append(ans)

print(sum(d)/len(a))
#print(d/len(a))

Submission status: Accepted

Solution code:
import math
import itertools
N= int(input())
zahyou=[list(map(int,input().split())) for i in range(N)]
lis = [i for i in range(N)]
permutations_lis=itertools.permutations(lis)
goukei=0
for i in permutations_lis:
    for j in range(N-1):
        goukei += math.sqrt(pow((zahyou[i[j+1]][0]-zahyou[i[j]][0]),2)+pow((zahyou[i[j+1]][1]-zahyou[i[j]][1]),2))
print(goukei/math.factorial(N))

Submission status: Accepted

Solution code:
import itertools, math
N = int(input())
L = [list(map(int, input().split())) for _ in range(N)]
orders = list(itertools.permutations(L))
d = 0
for order in orders:
    dist = 0
    for i in range(0,N-1):
        dist += math.sqrt((order[i][0]-order[i+1][0])**2 + (order[i][1]-order[i+1][1])**2)
    d += dist
print(d/len(orders))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools

#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

N = int(input())
ans = 0
xy = [list(map(int, input().split())) for _ in range(N)]
l = [int(x) for x in range(N)]
dist = 0
p = list(itertools.permutations(l, N))

for i in range(math.factorial(N)):
  for j in range(N-1):
    dist += math.sqrt((xy[p[i][j]][0]-xy[p[i][j+1]][0])**2+(xy[p[i][j]][1]-xy[p[i][j+1]][1])**2)
  ans += dist
  dist = 0

print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())

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

cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        cnt += np.sqrt((x[i] - x[j]) ** 2 + (y[i] - y [j]) ** 2)
        
ans = cnt * 2 / n

print(ans)

Submission status: Accepted

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

l = list(itertools.permutations(range(n)))
length = []
for perm in l:
    length.append(sum([math.sqrt((x[perm[i]]-x[perm[i+1]])**2+(y[perm[i]]-y[perm[i+1]])**2) for i in range(n-1)]))

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

Submission status: Accepted

Solution code:
from itertools import permutations
from math import sqrt

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

ans = 0
cnt = 0
base = list(range(0, N))
for order in permutations(base, N):
    cnt += 1
    for i in range(0, N - 1):
        n1 = order[i]
        n2 = order[i + 1]
        res = (XY[n1][0] - XY[n2][0]) ** 2
        res += (XY[n1][1] - XY[n2][1]) ** 2
        ans += sqrt(res)

print(ans / cnt)

Submission status: Accepted

Solution code:
from itertools import permutations as p
n, *d = map(int, open(0).read().split())
h = []
k = 0
for i in list(p(range(n))):
    for j in range(n - 1): # i[j], i[j+1]
        k += ((d[i[j] * 2] - d[i[j+1] * 2])**2 + (d[i[j] * 2 + 1] - d[i[j+1] * 2 + 1])**2)**.5
    h += [k]
    k = 0
print(sum(h) / len(h))

Submission status: Accepted

Solution code:
import itertools

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

for p in itertools.permutations(lis):
  dise = 0
  for i in range(N-1):
    #i i+i間の距離を求める
    dise += ((pos[p[i]][0]-pos[p[i+1]][0])**2+(pos[p[i]][1]-pos[p[i+1]][1])**2)**0.5
  dis.append(dise)

print(sum(dis)/len(dis))

Submission status: Accepted

Solution code:
n=int(input())
t=[]
for i in range(n):
    x,y=map(int,input().split())
    t.append([x,y])
sum=0
for p in range(n-1):
    for q in range(p,n):
        l=(t[p][0]-t[q][0])**2+(t[p][1]-t[q][1])**2
        sum+=l**(1/2)
print((2*sum)/n)

Submission status: Accepted

Solution code:
import itertools as it
import math

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

path = 0
p = it.permutations(xy)
for r in p:
    for i in range(N - 1):
        path += math.sqrt((r[i][0] - r[i + 1][0])**2 +
                          (r[i][1] - r[i + 1][1])**2)

res = path / math.factorial(N)
print(res)

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())
A = [list(map(int,input().split())) for i in range(N)]
P_num = math.factorial(N)
P = itertools.permutations(A)
ans = 0

for l in P:
    for i in range(N-1):
        ans += pow(pow(l[i+1][0]-l[i][0],2)+pow(l[i+1][1]-l[i][1],2),0.5)
print(ans/P_num)

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
points = []
for i in range(n):
    point = list(map(int,input().split()))
    points.append(point)
length = 0
for root in itertools.permutations(points):
    # print(root)
    for i in range(n-1):
        lengthi = math.sqrt((root[i][0]-root[i+1][0])**2+(root[i][1]-root[i+1][1])**2)
        # print(lengthi)
        length += lengthi
    # print(length)



print(length/(math.factorial(n)))

Submission status: Accepted

Solution code:
from itertools import*
n=int(input())

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

x=list(permutations(points))
y=0
for i in x:
    pre=i[0]
    for j in i[1:]:
        y+=((pre[0]-j[0])**2+(pre[1]-j[1])**2)**0.5
        pre=j
print(y/len(x))

Submission status: Accepted

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

def main():
    N = int(input())
    p = [list(map(int, input().split())) for _ in range(N)]
    s = 0.0
    for i in range(N - 1):
        for j in range(i + 1, N):
            s += math.sqrt((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)
    print(s*2/N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
#input = stdin.readlines
import math

def main():
    N = int(input())
    p = [list(map(int, input().split())) for _ in range(N)]
    s = 0.0
    for i in range(N - 1):
        for j in range(i + 1, N):
            s += math.sqrt((p[i][0] - p[j][0])**2 + (p[i][1] - p[j][1])**2)
    print(s*2/N)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N=int(input())
cord=[]
mylist=[]
answer=0
for i in range(N):
    cord=list(map(int,input().split()))
    mylist.append(cord)
    
    
#print(mylist)


def distance(a,b):
    l=math.sqrt((mylist[a][0]-mylist[b][0])**2+(mylist[a][1]-mylist[b][1])**2)
    return l

for i in range(N-1):
    for j in range(i+1,N):
        #print(i,j)
        answer+=distance(i,j)
        
        
print(answer*2/N)

Submission status: Accepted

Solution code:
import math
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
cd = []
for i in range(n):
    cd.append(iil())

dist = 0
for i in range(n):
    for j in range(i,n):
        dist += math.factorial(n-1)*2*((cd[i][0]-cd[j][0])**2+(cd[i][1]-cd[j][1])**2)**0.5
print(dist/math.factorial(n))

Submission status: Accepted

Solution code:
import sys
from math import sqrt
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A =[[int(_) for _ in input().split()] for i in range(n)]
    ans=0
    for i in range(n-1):
        for j in range(i+1,n):
            ans+=sqrt((A[i][0]-A[j][0])**2+(A[i][1]-A[j][1])**2)
    print(ans*2/n)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import sqrt
from itertools import permutations
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A =[[int(_) for _ in input().split()] for i in range(n)]
    a_list=list(permutations(A))
    a_len=len(a_list)
    ans_all=0
    for i in range(a_len):
        keiro = a_list[i]
        ans=0
        x0=keiro[0][0]
        y0=keiro[0][1]
        for x1,y1 in keiro[1:]:
            ans+=sqrt((x1-x0)**2+(y1-y0)**2)
        ans_all+=ans
    print(ans_all/a_len)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt
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 j != i:
      ans += sqrt((xy[i][0] - xy[j][0]) ** 2  + (xy[i][1] - xy[j][1]) ** 2)
print(ans/N)

Submission status: Accepted

Solution code:
from math import sqrt

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

result = 0
for i in range(N):
    for j in range(N):
        if i != j:
            result += sqrt((xy[i][0] - xy[j][0]) * (xy[i][0] - xy[j][0]) + (xy[i][1] - xy[j][1]) * (xy[i][1] - xy[j][1]))
print(result / N)

Submission status: Accepted

Solution code:
from math import sqrt, factorial
N = int(input())
x_y = {}
for i in range(N):
    x, y = map(int, input().split())
    x_y[i] = (x, y)

c = 0
d = 0
for i in range(N):
    _d = 0
    for j in range(N):
        if i != j:
            _x = (x_y[i][0] - x_y[j][0]) ** 2
            _y = (x_y[i][1] - x_y[j][1]) ** 2
            d += sqrt(_x + _y)
            c += 1

print(d * (N-1)/c)

Submission status: Accepted

Solution code:
import math
n = int(input())
dist = [[0]*n for _ in range(n)]
pos = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(n):
    for j in range(n):
        dist[i][j] = ((pos[i][0] - pos[j][0])**2 + (pos[i][1] - pos[j][1])**2)**0.5
from itertools import permutations
per = list(permutations([k for k in range(n)]))
count = 0
for pe in per:
    for l in range(n-1):
        count += dist[pe[l]][pe[l+1]]
ans = count/math.factorial(n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def f(n):
    if n==2:
        return [[1,2],[2,1]]
    else:
        new=[]
        l=f(n-1)
        for e in l:
            base=tuple(e)
            for m in range(len(e)+1):
                e=list(base)
                e.insert(m,n)
                new.append(e)
    return new

l=f(N)
a=[]
for e in l:
    total=0
    for n in range(len(e)-1):
        d=math.sqrt((X[e[n]-1]-X[e[n+1]-1])**2+(Y[e[n]-1]-Y[e[n+1]-1])**2)
        total+=d
    a.append(total)
ave=sum(a)/len(a)

print(ave)

Submission status: Accepted

Solution code:
N = int(input())
x,y = [],[]
for i in range(N):
    X,Y = [float(e) for e in input().split()]
    x.append(X)
    y.append(Y)

import itertools

ans = []
for order in itertools.permutations([i for i in range(N)]):
    r = 0.0
    for i in range(1,N):
        r += ((x[order[i]]-x[order[i-1]])**2 + (y[order[i]]-y[order[i-1]])**2) ** 0.5
    ans.append(r)

import numpy as np
print(np.mean(ans))

Submission status: Accepted

Solution code:

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

def dist(c,d):
    return ((c[0] - d[0])**2 + (c[1] - d[1])**2)**(1/2)

s = 0
for i in range(N):
    for j in range(i+1,N):
        s += dist(A[i],A[j])

print(2*s/N)

Submission status: Accepted

Solution code:
import itertools

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

def dist(lst):
	d = 0
	for i in range(n-1):
		lst1 = lst[i]
		lst2 = lst[i+1]
		d += ((lst1[0]-lst2[0])**2 + (lst1[1]-lst2[1])**2)**0.5
	return d

d = 0
p_lst = list(itertools.permutations(pos, n))

for v in p_lst:
	d += dist(v)
    
print(d / len(p_lst))

Submission status: Accepted

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

dists=[]
for i in perm:
    dist=0
    for j in range(1,n):
        dist+=((i[j][0]-i[j-1][0])**2+(i[j][1]-i[j-1][1])**2)**0.5
    dists.append(dist)
ans=sum(dists)/len(dists)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math

def d(a, b):
  return np.sum((a - b)**2)**0.5
  
N = int(input())

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

a = sum([[d(xy[i], xy[j]) for j in range(i+1, N)] for i in range(0, N)], [])

print(2*sum(a)/N)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
lista = []
anslist = 0
for i in range(n):
    x, y = map(int, input().split())
    lista.append([x, y])
# permutasion 引数１つのみ
# len(lista)!通り出る
for i in itertools.permutations(lista):
    for j in range(n - 1):
        anslist += math.sqrt((i[j + 1][0] - i[j][0]) ** 2 + (i[j + 1][1] - i[j][1]) ** 2)
        #if i != j:
            #print([lista[i], lista[j]])
            #anslist += math.sqrt((lista[j][0] - lista[i][0]) ** 2 + (lista[j][1] - lista[i][1]) ** 2)
# math.factorial 階乗
print(anslist / math.factorial(n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
x = []
for i in range(N):
  xi, yi = map(int, input().split())
  x.append((xi,yi))
  
sum_dist = 0
for i in range(len(x) - 1):
  for j in range(i+1, len(x), 1):
    sum_dist += ((x[i][0]-x[j][0])**2 + (x[i][1]-x[j][1])**2)**0.5
print(sum_dist*2/N)

Submission status: Accepted

Solution code:
from math import hypot

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

_sum = 0
for xi, yi in XY:
    for xj, yj in XY:
        _sum += hypot(xi-xj, yi-yj)

print(_sum/N)

Submission status: Accepted

Solution code:
# Problem C - Average Length

from itertools import permutations
import math

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

# initialization
pattern_list = []
moto = [i for i in range(1, N+1)]
distance = 0
patterns = list(permutations(moto))

# count
for p in patterns:
    for i in range(len(p)-1):
        point_1 = point_list[p[i]-1]
        point_2 = point_list[p[i+1]-1]
        tmp = math.sqrt((point_1[0]-point_2[0])**2 + (point_1[1]-point_2[1])**2)
        distance += tmp
distance = distance / len(patterns)

# output
print(distance)

Submission status: Accepted

Solution code:
from math import factorial, sqrt

def dist(x1, y1, x2, y2):
    return sqrt((x1 - x2)**2 + (y1 - y2)**2)


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

ans = 0
count = (N-1) * factorial(N) / (N * (N-1) / 2)

for i in range(N-1):
    for j in range(i+1, N):
        ans += dist(x[i], y[i], x[j], y[j]) * count

ans = ans / factorial(N)

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = 0
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        ans += math.sqrt(((XY[i][0]-XY[j][0])**2)+((XY[i][1]-XY[j][1])**2))

print(ans/N)

Submission status: Accepted

Solution code:
n  =int(input())
ls = []
for  i in range(n):
    x,y  =map(int,input().split())
    ls.append((x,y))
import itertools
ans = 0
cnt = 0
a = [i for i in range(n)]
for aa in itertools.permutations(a):
    cnt +=1
    idx = aa[0]
    xp,yp =  ls[idx]
    for idx in aa:
        x,y =  ls[idx]
        ans += ((x-xp)**2 + (y-yp)**2)**0.5
        xp ,yp = x,y
print(ans/cnt)

Submission status: Accepted

Solution code:
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    X, Y = [0] * N, [0] * N
    for i in range(N):
        X[i], Y[i] = map(int, input().split())
    A=[i for i in range(N)]
    ans = 0
    cnt=0
    for k in permutations(A,N):
        for i in range(N-1):
            ans+=np.sqrt((X[k[i]]-X[k[i+1]])**2+(Y[k[i]]-Y[k[i+1]])**2)
        cnt+=1

    print(ans/cnt)

resolve()

Submission status: Accepted

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

d = 0
c = 0
for x in itertools.permutations(xy):
  c += 1
  D = 0
  for i in range(N-1):
    D += ((x[i][0]-x[i+1][0]) ** 2 + (x[i][1]-x[i+1][1]) ** 2) ** 0.5
  d += D
ans = d / c
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt

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

for i in range(n - 1):
    for j in range(i, n):
        xi, yi = p[i]
        xj, yj = p[j]
        total += sqrt((xi -xj) ** 2 + (yi - yj) ** 2)

ans = total / n * 2
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations

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

dist = 0
cnt = 0
for pattern in permutations(xy):
    cnt += 1
    for i in range(n - 1):
        x1, y1 = pattern[i]
        x2, y2 = pattern[i + 1]
        dist += pow(pow(x1 - x2, 2) + pow(y1 - y2, 2), 1 / 2)
res = dist / cnt
print(res)

Submission status: Accepted

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

import math

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

print(dist_sum / N)

Submission status: Accepted

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

from math import sqrt
def dist(a,b):
    return sqrt((a[0]-b[0])**2 + (a[1]-b[1])**2)
from itertools import permutations
a=b=0
for p in permutations(range(N)):
    b+=1
    for i in range(N-1):
        a+=dist(XY[p[i]], XY[p[i+1]])
print(a/b)

Submission status: Accepted

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

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

import math
import itertools
ans = 0
for p in list(itertools.permutations(range(n))):
    for i in range(len(p)):
        if i == len(p)-1:
            continue
        ans += math.sqrt((X[p[i]]-X[p[i+1]])**2+(Y[p[i]]-Y[p[i+1]])**2)
ans /= math.factorial(n)
print(ans)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
N = int(input())
X, Y = zip(*tuple(map(int, input().split()) for _ in range(N)))


def dist(x, xx, y, yy):
    return ((x - xx) ** 2 + (y - yy) ** 2) ** 0.5


d = 0
for p in permutations(range(N)):
    tmp = 0
    for s, t in zip(p, p[1:]):
        x = X[s]
        y = Y[s]
        xx = X[t]
        yy = Y[t]
        tmp += dist(x, xx, y, yy)
    d += tmp

print(d/factorial(N))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    XY = [[int(i) for i in input().split()] for j in range(N)]
    from itertools import permutations
    from math import hypot
    ans = 0
    for p in permutations(range(N)):
        cur = 0
        pre = p[0]
        for i in p[1:]:
            cur += hypot(XY[pre][0] - XY[i][0], XY[pre][1] - XY[i][1])
            pre = i
        ans += cur
    fa = 1
    for i in range(2, N+1):
        fa *= i
    print(ans/fa)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
xy = [LIST() for _ in range(n)]
c = list(permutations(xy, n))
ans = 0
for i in range(len(c)):
    for j in range(1, n):
        ans += sqrt((c[i][j][0] - c[i][j - 1][0]) ** 2 + (c[i][j][1] - c[i][j - 1][1]) ** 2)
ans /= len(c)
print(ans)