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
from math import sqrt


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


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

    a = permutations(town_list, len(town_list))

    for v in a:
        tmp = 0
        for i in range(len(v) - 1):
            tmp += calc_dist(v[i], v[i + 1])
        ans_list.append(tmp)

    print(sum(ans_list) / len(ans_list))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
import itertools

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


# print(x)
# print(y)

def root(xi, yi, xj, yj):
    return math.sqrt((xi - xj) ** 2 + (yi - yj) **2)

# print(root(1, 0, 0, 0))
# print(root(0, 0, 0, 1))


# a = root(4, 3, 6, 2)
# print(a)



# x1 = (-406, 10)
# x2 = ( 512, 859)
# x3 = ( 494, 362)
# x4 = (-955, -475)
# x5 = ( 128, 553)
# x6 = (-986, -885)
# x7 = ( 763, 77)
# x8 = ( 449, 310)
#

l = x
# print(l)
# l = [x1, x2, x3, x4, x5, x6, x7, x8]

m = 0
for i in itertools.permutations(l, len(l)):
    k = 0
    for j in range(len(i) -1):
        k += root(*(i[j] + i[j+1]))
    m += k
print(m/math.factorial(len(l)))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import copy

def calc_distance(town1, town2):
    distance_pow = (town1[0] - town2[0])**2 + (town1[1] - town2[1])**2
    distance = math.sqrt(distance_pow)
    return distance

def calc(L, done_towns, todo_towns):
    sum = 0
    if len(todo_towns) == 1:
        done_towns.append(todo_towns[0])
        distance = 0
        while(len(done_towns) >= 2):
            first_town = done_towns.pop(0)
            second_town = done_towns[0]
            min_town = min(first_town, second_town)
            max_town = max(first_town, second_town)
            distance += L[min_town*10 + max_town]
        return distance

    for town in todo_towns:
        new_done_towns = copy.copy(done_towns)
        new_todo_towns = copy.copy(todo_towns)
        new_done_towns.append(town)
        new_todo_towns.remove(town)
        sum += calc(L, new_done_towns, new_todo_towns)

    return sum

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

L = [0] * 78

# 全経路
for i in range(N):
    for j in range(i+1, N):
        L[i*10 + j] = calc_distance(town_points[i], town_points[j])

sum_distance = calc(L, [], list(range(N)))
N_factorial = math.factorial(N)
average_distance = sum_distance / N_factorial

print(average_distance)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
A =[0]*N
B =[0]*N
su =0
count=0
for i in range(N):
  A[i],B[i] =map(int, input().split())
for i in itertools.permutations(range(N)):
  count +=1
  for j in range(1,len(i)):
    su += math.sqrt((A[i[j]]-A[i[j-1]])**2+(B[i[j] ]-B[i[j-1]])**2)
print(su/count)

Submission status: Accepted

Solution code:
import itertools

def calculate_distance(o, n):
    return ((o[0]-n[0])**2 + (o[1]-n[1])**2)**0.5

n = int(input())
position = []
distance_list = []

for _ in range(n):
    position.append(list(map(int, input().split())))


for target in itertools.permutations(position):
    old = target[0]
    distance = 0
    for new in target:
        distance += calculate_distance(old, new)
    distance_list.append(distance)

print(sum(distance_list)/len(distance_list))

Submission status: Accepted

Solution code:
import math

num = int(input())
co = []

for i in range(num):
    co.append(list(map(int, input().split())))

#print(co)
pat = math.factorial(num)
#print(pat)
num -= 1
dis = 0

for i in range(num):
    for j in range(num):
        dis += math.sqrt((co[i][0]-co[j+i+1][0])**2 + (co[i][1]-co[j+i+1][1])**2)
        if num == j+i+1: break

dis *= 2/(num+1)

print(dis)

Submission status: Accepted

Solution code:
n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
def kaijo(a):
    s = 1
    for i in range(2,a+1):
        s = s * i
    return(s)
l = []
for i in range(n):
    for j in range(n):
        if not i == j:
            l.append(((x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2)**0.5)
print(sum(l)*kaijo(n-1)/kaijo(n))

Submission status: Accepted

Solution code:
import math

N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
p = P
r = 0
n = (N*(N-1))/2
s = N * (N -1)

while len(p) != 1:
    for i in range(len(p)-1):
        r = r + math.sqrt(pow((p[0][0]-p[i+1][0]),2) + (pow((p[0][1]-p[i+1][1]),2)))
    p = p[1:len(p)]

print((r*((s*2)/N))/s)

Submission status: Accepted

Solution code:
import math

N = int(input())

cors = []
for i in range(N):

    xy = input().split()
    cors.append(xy)

sumnum = 0

n = 0
for i in range(N):

    for j in range(i,N):
        if i == j:
            continue
        else:
            n = n+1
            #print("i="+str(i) +"j="+str(j))
            xi = int(cors[i][0])
            xj = int(cors[j][0])
            yi = int(cors[i][1])
            yj = int(cors[j][1])
            sumnum = sumnum + math.sqrt((xj-xi)*(xj-xi)+(yj-yi)*(yj-yi))
print(sumnum/n*(N-1))

Submission status: Accepted

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

Submission status: Accepted

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

entHai = []

def newHai(preHai, hai):
    global entHai
    if len(hai) == 1:
        entHai.append(preHai+hai)

    #print(hai)
    for h in hai:
        narr = [na for na in hai if na != h]
        #print("narr:",narr)
        narr = newHai(preHai + [h], narr)
        #print("narR:",narr)

newHai([], list(range(N)))

keiroSum = 0
for eh in entHai:
    #print(eh)
    for nn in range(1, N):
        xi, yi = xy[eh[nn-1]]
        xj, yj = xy[eh[nn]]
        keiroSum += pow((xi-xj)**2 + (yi-yj)**2, 0.5)

print(keiroSum/len(entHai))

Submission status: Accepted

Solution code:
import math
import itertools

n = input()
n = int(n)
nlist = []
for i in range(0,n):
    nlist.append(input().split())

#nの階上
njunretu = []
for i in range(0,n):
    njunretu.append(i)

#全ての順列が求まった
jlist = list(itertools.permutations(njunretu,n))

result = 0
for i in range(0,len(jlist)):
    for j in range(0,n-1):
        f = jlist[i][j]
        l = jlist[i][j+1]
        result += math.sqrt(((int(nlist[f][0]) - int(nlist[l][0]))**2) + ((int(nlist[f][1]) - int(nlist[l][1]))**2))

print(result / len(jlist))

Submission status: Accepted

Solution code:
n=int(input())
city=[]
for i in range(n):
  l = list(map(lambda x: int(x),input().split()))
  #print(l)
  city.append(l)
  
#print(city)

dist=0
for i in range(n):
  for j in range(i,n):
    #print(l[i])
    dist += ((city[i][0]-city[j][0])**2+(city[i][1]-city[j][1])**2)**0.5
    #print(dist)

x = n*(n-1)/2

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

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

if x==1:
  print(dist)
else:
  print(dist*2/n)

Submission status: Accepted

Solution code:
N=int(input())
import math
x=[0]*N
y=[0]*N
sum = 0.0
for i in range(N):
    x[i],y[i]=map(int, input().split())
for i in range(N):
    for j in range(N):
        sum = sum + math.sqrt(pow((x[i]-x[j]),2)+pow((y[i]-y[j]),2))
        #print(x[i],y[i],x[j],y[j],sum)
print(sum/N)

Submission status: Accepted

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

lenlis = []
cnt = 0
for v in itertools.permutations(range(n+1)[1:], n):
    cnt += 1
    lenlis.append([])
    for i in range(len(v)):
        if i != len(v)-2:
            lenlis[cnt-1].append(dislis[v[i-1]-1][v[i]-1])
anslis = []
cntcnt = 0
for i in lenlis:
    anslis.append(sum(lenlis[cntcnt]))
    cntcnt += 1
print(sum(anslis)/len(anslis))

Submission status: Accepted

Solution code:
N = int(input())
a = [input() for i in range(N)]
an_list = []

for i in range(N):
    for j in reversed(range(N)):
        b, c = [int(x) for x in a[i].split()]
        d, f = [int(x) for x in a[j].split()]
        an_list.append((((b - d) ** 2 + (c - f) ** 2) ** 0.5))

print(sum(an_list)/N)

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())

pos = list()

for i in range(N):
    pos.append(tuple(map(int, input().split())))

dists = dict()
for i in range(N):
    for j in range(i+1, N):
        dists[(i, j)] = math.sqrt(
            (pos[i][0]-pos[j][0])**2+(pos[i][1]-pos[j][1])**2)

total = 0
num = 0

for i in itertools.permutations(range(N)):
    num += 1
    pre = None
    for j in i:
        if pre is None:
            pre = j
            continue
        if pre > j:
            f = j
            t = pre
        else:
            t = j
            f = pre
        total += dists[(f, t)]

print(total/num)

Submission status: Accepted

Solution code:
#C
n = int(input())
x = [0]*n
y = [0]*n
kyori = 0
for i in range(n):
    x[i],y[i] = map(int,input().split())
import math
for j in range(n):
    for k in range(n):
        kyori += math.sqrt((x[j]-x[k])**2+(y[j]-y[k])**2)
print(kyori/n)

Submission status: Accepted

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

#必要な掛け算の数字を出す
k=math.factorial(N) #k通り
w=0
for i in range(0,N):
    w=w+(N-i-1)
#必要な数
t=(k*(N-1))/(w)
#それぞれの辺の長さを総当たりで求めていく
p=0
q=0
for i in range(0,N):
    for j in range(i+1,N):
        p=(x[i][0]-x[j][0])**2+(x[i][1]-x[j][1])**2
        q=q+math.sqrt(p)
print(q*t/k)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

n = int(input().strip())
xy = []
for i in range(n):
    xy.append([int(j) for j in input().strip().split()])

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

d = 0
for g in range(n):
    for h in range(g+1, n):
        d += dist(xy[g], xy[h])

       
print(2*d/n)

Submission status: Accepted

Solution code:
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())

x = [0] * n
y = [0] * n

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


sum = 0
c = 0

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

if n == 2:
    print(sum)
else:
    print(sum * 2 / n )

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
towns = []
indexs = []
for i in range(n):
    tmp = input().split(' ')
    x = int(tmp[0])
    y = int(tmp[1])
    towns.append([x,y])
    indexs.append(i)

sum = 0
c = 0
for index in itertools.permutations(indexs):
    c = c + 1
    for k in range(len(index)-1):
        i = towns[index[k]]
        j = towns[index[k+1]]
        sum = sum + math.sqrt(pow((i[0] - j[0]),2) + pow((i[1] - j[1]), 2))
print(sum/c)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
XY=[list(map(int,input().split())) for i in range(N)]
value=0
for i in range(N):
    for m in range(i+1,N):
        x0,y0,x1,y1=XY[i][0],XY[i][1],XY[m][0],XY[m][1]
        value+=(((x0-x1)**2+(y0-y1)**2)**0.5)
print(value*2/N)

Submission status: Accepted

Solution code:
import itertools
import math

n=int(input())
#print(n)
p=list(itertools.permutations(range(n)))
l=[]
for i in range(n):
    la=list(map(int,input().split()))
    l.append(la)
ans=0
for i in p:
    for j in range(1,n):
        tmp=0
        tmp+=(l[i[j]][0]-l[i[j-1]][0])**2
        tmp+=(l[i[j]][1]-l[i[j-1]][1])**2
        ans+=math.sqrt(tmp)
ans/=(len(p)) 
print(ans)

Submission status: Accepted

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

bl={}
for i in range(n):
    bl[i]=0
l=[0]*n

ans_pl=[]




def qpl(index):
    global l
    if index==n:
        ans_pl.append(list(l))
        return
    for i in range(n):
        if bl[i]==0:
            l[index]=i
            bl[i]=1
            qpl(index+1)
            bl[i]=0
qpl(0)


# for item in ans_pl:
    # print(item)




summ=0
for i in range(len(ans_pl)):
    ll=ans_pl[i]
    pre_x,pre_y=d[ll[0]][0],d[ll[0]][1]
    for j in range(1,n):
        x,y=d[ll[j]][0],d[ll[j]][1]
        summ+=((x-pre_x)**2+(y-pre_y)**2)**0.5
        pre_x,pre_y=x,y

print(summ/len(ans_pl))

Submission status: Accepted

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

for i, nowX in enumerate(itertools.permutations(x,N)):
    for j in range(N-1):
        sumX[i] += dis[nowX[j]][nowX[j+1]]

result = sum(sumX)/(math.factorial(N))
print(result)

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

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

ans = S / N
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
list = []
for i in range(n):
    #print("a")
    li=[int(i) for i in input().split()]
    list.append(li)
#print(list)
count = 0
for i in range(n-1):
    for j in range(n-i-1):
        #print(((list[i][0]-list[i+j+1][0])**2+(list[i][1]-list[i+j+1][1])**2)**0.5)
        count += ((list[i][0]-list[i+j+1][0])**2+(list[i][1]-list[i+j+1][1])**2)**0.5

#print(count)

nc2 = n*(n-1)//2

print(count*(n-1)/nc2)

Submission status: Accepted

Solution code:
import math
N = int(input())
x = []
y = []
for i in range(N):
    tx,ty=map(int,input().split())
    x.append(tx)
    y.append(ty)
sumv = 0
for i in range(N):
    for k in range(N-i-1):
        dis = math.sqrt((y[i]-y[N-k-1])**2+(x[i]-x[N-k-1])**2)
        sumv += dis
print(2/N*sumv)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

N=int(input())
zahyo=[input().split() for i in range(N)]

dis=[0]*(int(0.5*(N-1)*N))
k=0
for i in range(0,N-1):
    for j in range(i+1,N):
        dis[k]=math.sqrt((int(zahyo[i][0])-int(zahyo[j][0]))*(int(zahyo[i][0])-int(zahyo[j][0]))+(int(zahyo[i][1])-int(zahyo[j][1]))*(int(zahyo[i][1])-int(zahyo[j][1])))
        k+=1

add=0
ans=0
for i in range(0,int((N*(N-1))/2)):
    add+=dis[i]

ans=add*math.factorial(N-1)*2

print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
from itertools import permutations

def c():
    n = int(input())
    points = []
    paths = permutations(range(n), n)

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

    dist = [[float('inf') for _ in range(n)] for _ in range(n)]

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

    sum_length = 0
    count = 0
    for path in paths:
        count += 1
        for i in range(1, len(path)):
            sum_length += dist[path[i-1]][path[i]]

    print(sum_length / count)

if __name__ == '__main__':
    c()

Submission status: Accepted

Solution code:
n = int(input())
x = []
y = []
for i in range(n):
    xx, yy = map(int, input().split())
    x.append(xx)
    y.append(yy)
import sys
sys.setrecursionlimit(2000)
import math

def dfs(v, r, visited):
    visited[v] = 1
    global ans
    for i in range(n):
        if visited[i] == 0:
            r += math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
            dfs(i, r, visited)
            visited[i] = 0
            r -= math.sqrt((x[i] - x[v]) ** 2 + (y[i] - y[v]) ** 2)
        elif visited == [1] * n:
            ans += r
            return
ans = 0
for i in range(n):
    visited = [0 for _ in range(n)]  
    dfs(i, 0, visited)
div = 1
for i in range(1, n+1):
    div *= i
print(ans / div )

Submission status: Accepted

Solution code:
### C
from itertools import combinations
from math import factorial
from scipy.misc import comb

N = int(input())

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

len_all = 0
for i, j in combinations(range(N), 2):
    len_all += ((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
one_ave = len_all / comb(N,2)

print(one_ave*(N-1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
from statistics import mean
from functools import reduce, lru_cache
from itertools import permutations


@lru_cache()
def distance(p1, p2):
    return math.sqrt(sum([(a - b) ** 2 for a, b in zip(p1, p2)]))


def distances(arr):
    return [distance(arr[i], arr[i+1]) for i in range(len(arr)-1)]


def main(n: int, points: list):
    ret = []
    for x in permutations(points):
        ret.append(sum(distances(x)))

    print(mean(ret))


if __name__ == '__main__':
    n = int(input())
    a = [input() for i in range(n)]

    points = [s.split(' ') for s in a]

    main(
        n,
        [(int(p[0]), int(p[1])) for p in points]
    )

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read

def main():
    import numpy as np
    import math
    *ns, = map(int, read().split())
    n, s = ns[0], ns[1:]
    s = np.array(s).reshape([len(s)//2,2])
    ds = np.array([])
    for i in range(n):
        for j in range(i+1, n):
            xyi, xyj = s[i], s[j]
            ds = np.append(ds, ((xyi[0]-xyj[0])**2+(xyi[1]-xyj[1])**2)**0.5)
    p = math.factorial(n)
    p2 = p*(n-1)//len(ds)
    print(sum(ds*p2)/p)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

x = []
y = []

sm = 0

for _ in range(n):

    tmp_x, tmp_y = map(int, input().split())
    
    if len(x)>0:
        for i in range(_):
            diff = ((tmp_x - x[i])**2 + (tmp_y - y[i])**2)**0.5
            sm += diff       
    x.append(tmp_x)
    y.append(tmp_y)

print (2*sm/n)

Submission status: Accepted

Solution code:
import math

N=int(input())
townX=[]
townY=[]
for j in range(N):
  x,y=map(int,input().split())
  townX.append(x)
  townY.append(y)

#print(townX,townY)

dist =0
if N==2:
  print(math.sqrt( (townX[0]-townX[1])**2 +(townY[0]-townY[1])**2 ))
else:
 for i in range(N-1):
   for j in range(i+1,N):
    dist += math.sqrt( (townX[i]-townX[j])**2 +(townY[i]-townY[j])**2 )
      
 dist=((N*(N-1)/2) -(N-2)*(N-1)/2)*dist    
 print(2*dist/(N*(N-1)))
  
#print(math.factorial(6))

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())

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

P = list(itertools.permutations(XY,r = N))

D = math.factorial(N)

area = 0

for i in range(0,len(P)):
  p = P[i]
  for j in range(0,N - 1):
    x = (p[j][0] - p[j + 1][0]) ** 2
    y = (p[j][1] - p[j + 1][1]) ** 2
    area += math.sqrt(x + y)
  
print(area / D)

Submission status: Accepted

Solution code:
import itertools as it

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

s = ''
for i in range(n):
    s += str(i)
g = 0.0
for sb in it.permutations(s, n):
    tmpli = list(sb)
    for j in range(n-1):
        length_x = abs(xp[int(tmpli[j])]-xp[int(tmpli[j+1])])
        length_y = abs(yp[int(tmpli[j])]-yp[int(tmpli[j+1])])
        length_t = (length_x*length_x + length_y*length_y)**0.5
        g += length_t
print(g/fibn)

Submission status: Accepted

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

x_dis_list = []
y_dis_list = []
for i in range(n - 1):
    for j in range(i + 1, n):
        x_dis = (x[i] - x[j]) ** 2
        y_dis = (y[i] - y[j]) ** 2
        x_dis_list.append(x_dis)
        y_dis_list.append(y_dis)

tmp = 0
tmp_only = 0
if n == 2:
    tmp_only = math.sqrt(x_dis_list[0] + y_dis_list[0])
else:
    for i in range(len(x_dis_list)):
        tmp += math.sqrt(x_dis_list[i] + y_dis_list[i])

if n == 2:
    print(tmp_only)
else:
    print((2* tmp / n))

Submission status: Accepted

Solution code:
import sys
import math
import copy
import itertools
from functools import lru_cache


def pythagorean(x1, x2, y1, y2):
    z = (x1 - x2) ** 2 + (y1 - y2) ** 2
    if z > 0:
        return math.sqrt(z)
    else:
        return 0

# @lru_cache()
# def route(summ, now, m, li, x, y):
#     if m == 0:
#         noww = 0
#     summm = 0
#     for g in li:
#         noww = now + pythagorean(x[m], x[g], y[m], y[g])
#         if len(li) != 1:
#             retun = summ + now
#         else:
#             lii = copy.deepcopy(li)
#             lii.remove(g)
#             summm += route(summ, noww, g, x, y)
#     return summm

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

summ = 0
for v in itertools.permutations(range(n)):
    noww = 0
    for nn in range(1, n):

        noww += pythagorean(x[v[nn -1]], x[v[nn]], y[v[nn -1]], y[v[nn]])
    summ += noww

print(summ / math.factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools


N = int(input())
xy = []
for i in range(N):
    xy.append(list(map(int, input().split())))
    
length = 0
for positions in itertools.permutations(xy, N):
    ahead = positions[0]
    for pos in positions[1:]:
        length += ((ahead[0] - pos[0]) ** 2 + (ahead[1] - pos[1]) ** 2) ** 0.5
        ahead = pos
print(length / math.factorial(N))

Submission status: Accepted

Solution code:
import math

n = int(input())
x = []
y = []

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

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

num = 1

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

ans = 0

for i in range(n):
    for j in range(n):
        ans += dist[i][j] * (num / n)

ans /= num
print(ans)

Submission status: Accepted

Solution code:
import math
n=int(input())
z=[list(map(int,input().split())) for i in range(n)]
a=math.factorial(n)
b=0
for i in range(n):
  for j in range(n):
    b=b+((z[i][0]-z[j][0])**2+(z[i][1]-z[j][1])**2)**0.5
print((math.factorial(n)/n)*b/a)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
sv = [[0 for i in range(n)] for _ in range(n)]
num = [j for j in range(n)]
d = []
dis_sum = 0
count = 0
count2 = 0

for _ in range(n):
    tmpx, tmpy = map(int, input().split())
    d.append([tmpx, tmpy])

for v in itertools.permutations(num, n):
    count += 1
    v = list(v)
    for i in range(n - 1):
        if sv[v[i]][v[i + 1]] != 0:
            dis_sum += sv[v[i]][v[i + 1]]
        else:
            tmp1, tmp2 = d[v[i]][0] - d[v[i + 1]][0], d[v[i]][1] - d[v[i + 1]][1]
            tmp = math.sqrt(abs(tmp1) ** 2 + abs(tmp2) ** 2)
            dis_sum += tmp
            sv[v[i]][v[i + 1]] = tmp

print(dis_sum / count)

Submission status: Accepted

Solution code:
import copy

N = int(input())
xy = []

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


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

ans = 0
def calcdistance(visited,distances,total,start):
    global ans
    visited2 = copy.deepcopy(visited)
    visited2[start] = 1
    if 0 in visited2:
        for i in range(N):
            if visited2[i] == 0:
                calcdistance(visited2,distances,total+distances[start][i],i)
        return
    else:
        ans += total
        return

for i in range(N):
    calcdistance([0]*N,distances,0,i)
    
kaijo = 1
for i in range(1,N+1):
    kaijo *= i
    
print(ans/kaijo)

Submission status: Accepted

Solution code:
import math
N=int(input())
f_list=[[int(thing) for thing in input().split()] for i in range(N)]

def distance(f_1,f_2):
    return math.sqrt((f_1[0]-f_2[0])**2+(f_1[1]-f_2[1])**2)
l=[]
for i in range(N-1):
    for j in range(i+1,N):
        l.append(distance(f_list[i],f_list[j]))
print((N-1)*sum(l)/len(l))

Submission status: Accepted

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

#print(l[1][1])
Nroot = 0
Nsta = 0
Nkai = 1
Nre = 0
ans =0

for m in range(N):
    Nroot += m
#    print(Nroot)

for o in range(N):
    Nkai = Nkai * (o+1)
#    print(Nkai)

Nre = (Nkai * (N-1)) / Nroot

for j in range(N-1):
    for k in range(N-(j+1)):
        dis = ((l[j][0]-l[k+j+1][0])**2 + (l[j][1]-l[k+j+1][1])**2)**0.5
#        print("j",j, "k", k, dis)
        ans += (dis * Nre) / Nkai

print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

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

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

sum_one_dis = 0
sum_all = 0

cnt = 0
for i in itertools.permutations([i for i in range(n)]):
    k = list(i)
    for idx in k:
      if idx >= 1:
        sum_one_dis += distance(x[i[idx-1]], y[i[idx-1]], x[i[idx]], y[i[idx]])
    cnt += 1

ave = sum_one_dis / cnt
print(round(ave, 10))

Submission status: Accepted

Solution code:
n=int(input())
s=0
arr=[]
import math
def get_distance(x1, y1, x2, y2):
  d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
  return d
for i in range(n):
  arr.append(input().split())
arr.append(arr[0])
for i in range(n):
  for j in range(i+1,n):
  	s+= get_distance(int(arr[i][0]),int(arr[i][1]),int(arr[j][0]),int(arr[j][1]))
print(2*s/n)

Submission status: Accepted

Solution code:
import itertools
import math
n = int(input())
p = [list(map(int, input().split())) for i in range(n)]
r = 0 
for l in itertools.permutations(p):
        for i in range(len(l)-1):
                r += math.sqrt((l[i][0] - l[i+1][0])**2 + (l[i][1] - l[i+1][1])**2)
print(r/math.factorial(n))

Submission status: Accepted

Solution code:
N=int(input())
X=[]
Y=[]
for i in range(N):
  x,y=map(int,input().split())
  X +=[x]
  Y +=[y]
L=0#全点同士の距離の合計
for i in range(N-1):
  for j in range(i+1,N):
    L+= (((X[i]-X[j])**2)+((Y[i]-Y[j])**2))**0.5
    
print(L*2/N)

Submission status: Accepted

Solution code:
import numpy as np
 
n = int(input())
li = [[int(i) for i in input().split()] for _ in range(n)]
arr = np.array(li)

tmp_index = np.arange(arr.shape[0])
x, y = np.meshgrid(tmp_index, tmp_index)
distances = np.linalg.norm(arr[x]-arr[y], axis=2)
print(np.sum(distances) / n)

Submission status: Accepted

Solution code:
import math

n = int(input())

x_y = [[int(_) for _ in input().split(' ')] for _ in range(n)]

s = 0.0
for i in range(n):
    for j in range(i + 1, n):
        s += ((x_y[i][0] - x_y[j][0])**2.0 + (x_y[i][1] - x_y[j][1])**2.0)**0.5

print(s * 2 * (n - 1) * math.factorial(n - 2) / math.factorial(n))

Submission status: Accepted

Solution code:

import math as mm
def fac(n):
    return 1 if (n==1 or n==0) else n * fac(n - 1);
def lenn(*a):
    #print("a;sldkfj",a)
    return mm.sqrt((a[2]-a[0])**2+(a[3]-a[1])**2)
def dist(*a):
    return(mm.sqrt((a[2]-a[0])**2+(a[3]-a[1])**2))

from itertools import permutations
n=int(input())
a=[]
anss=0
for i in range(n):
    a.append(list(map(int,input().split())))
for i in permutations(a):
    for j in range(len(i)-1):
        anss+=dist(i[j][0],i[j][1],i[j+1][0],i[j+1][1])
g=anss/fac(n)
print('{0:.10f}'.format(g))

Submission status: Accepted

Solution code:
N = int(input())
x_y = [[int(_) for _ in input().split(" ")] for _ in range(N)]

n_path = 1
for i in range(N):
    n_path = n_path * (i + 1)

import math

distance_list = []
for i in range(N * (N-1)):
    j = i + 1
    while j < N:
        distance = math.sqrt((x_y[i][0] - x_y[j][0])**2 + (x_y[i][1] - x_y[j][1])**2)
        distance_list.append(distance)
        j = j + 1

print(sum(distance_list) * 2/N )