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:
N = int(input())
X = []
Y = []
D = 0
F = [1]
for i in range(N):
    F.append(F[i]*(i+1))
E = F[N-2]*(N-1)
E = E/F[N]
for i in range(N):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)
for i in range(N):
    xi,yi = X[i],Y[i]
    for j in range(i,N):
        xj,yj = X[j],Y[j]
        d=((xj-xi)**2+(yj-yi)**2)**0.5
        D+= d
print(D*E*2)

Submission status: Accepted

Solution code:
import math
import functools
import itertools
import operator

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


@functools.lru_cache(maxsize=None)
def dis(i, j):
    start = points[i]
    end = points[j]
    x1, x2 = start[0], end[0]
    y1, y2 = start[1], end[1]
    return math.sqrt((x1 - x2) ** 2 + (y1 - y2) ** 2)


def pairwise(iterable):
    a, b = itertools.tee(iterable)
    next(b, None)
    return zip(a, b)


def factorial(n):
    return functools.reduce(operator.mul, range(1, n + 1))


s = 0
for path in itertools.permutations(range(N)):
    d = sum(dis(p, q) for p, q in pairwise(path))
    s += d
print(s / factorial(N))

Submission status: Accepted

Solution code:
a=int(input())
P = [input().split() for i in range(a)]
#print(P)
import itertools
L=list(itertools.permutations(range(a)))

N=[0]
for l in L:
  A=0
  #print(l)
  for i in range(a-1):
    n0 = int(l[i])
    n1 = int(l[i+1])
    A += (((int(P[n0][0]) - int(P[n1][0])) ** 2) + ((int(P[n0][1]) - int(P[n1][1])) ** 2)) ** 0.5
  N.append(A)
#print(N)
print(sum(N)/len(L))

Submission status: Accepted

Solution code:
import math

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

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

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

Submission status: Accepted

Solution code:
import itertools
n=int(input())
size=1
for i in range(1,n+1):
  size*=i
#print(size)
x=[]
y=[]
dist=0
aved=0
seq=[i+1 for i in range(n)]
#print(seq)
p=list(itertools.permutations(seq))
#print(p)
for i in range(n):
  a,b=map(int,input().split())
  x.append(a)
  y.append(b)
for i in range(size):
  for j in range(n-1):
    dist+=((x[p[i][j]-1]-x[p[i][j+1]-1])**2+(y[p[i][j]-1]-y[p[i][j+1]-1])**2)**0.5
aved=dist/size
print(aved)

Submission status: Accepted

Solution code:
import math

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

import itertools
seq=list(range(n))
wa=0

for p in itertools.permutations(seq,n):
  for i in range(n-1):
    x=(town[p[i]][0]-town[p[i+1]][0])**2
    y=(town[p[i]][1]-town[p[i+1]][1])**2
    temp=(x+y)**(1/2)
    wa+=temp
print(wa/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools 
n = int(input())
perms = list(itertools.permutations(list(range(n))))
xy = []
for i in range(n):
    a, b = map(int, input().split())
    xy.append([a, b])
ans = 0
for perm in perms:
    length = len(perm)
    dist = 0;
    for i in range(length-1):
        ind = perm[i]
        ind1 = perm[i+1]
        dist += ((xy[ind][0]-xy[ind1][0])**2 + (xy[ind][1]-xy[ind1][1])**2)**(1/2)
    ans += dist
print(ans/len(perms))

Submission status: Accepted

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

import math
N = int(input())
li = []
for i in range(N):
    li.append(input().split())
    
def distance(x1,y1,x2,y2):
    return math.sqrt((float(x1)-float(x2))**2+(float(y1)-float(y2))**2)

import itertools
li1 = list(itertools.permutations(li))
Sum_Sum = 0
for i in range(len(li1)):
    Sum = 0
    for j in range(len(li1[i])-1):
        Sum += distance(li1[i][j][0],li1[i][j][1],li1[i][j+1][0],li1[i][j+1][1])
    Sum_Sum += Sum
print("{:.10f}".format(Sum_Sum/len(li1)))

Submission status: Accepted

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

Submission status: Accepted

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

d_sum=0
for i in range(n-1):
    for j in range(i+1,n):
        x=(loc[j][0]-loc[i][0])**2
        y=(loc[j][1]-loc[i][1])**2
        dij=math.sqrt(x + y)
        d_sum+=dij
print(2*d_sum/n)

Submission status: Accepted

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

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

sum = 0
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        sum += math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)

ans = sum / n
print(ans)

Submission status: Accepted

Solution code:
import math
def fact(x):
    if x == 0 or x == 1:
        return 1

    ans = 1
    for i in range(1,x+1):
        ans *= i
    return ans
def combi(n,r):
    return fact(n)//((fact(r))*(fact(n-r)))


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

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

print(D*fact(N-1)/( fact(N-2)*(combi(N,2)) ))

Submission status: Accepted

Solution code:
import math

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

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

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

NPATH = 1
for i in range(1,N):
    NPATH *= i
NPATH *= 2

dst = 0.0
for i in range(N-1):
    for j in range(i+1,N):
        dst += dist(p[i], p[j])
print(dst * NPATH / NALL)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
p = list(list(map(int,input().split()))for _ in range(N))

orders = list(itertools.permutations(range(N),N))
dist = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist += ((p[i][0]-p[j][0])**2+(p[i][1]-p[j][1])**2)**0.5
ans = dist*2/N
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import math
import itertools
def main():
    N = int(input())
    town_zahyou = [ [int(s) for s in input().split()] for i in range(N)]

    sum_route = 0

    for junban_list in list(itertools.permutations(town_zahyou, N)):
        route = 0
        for i, town in enumerate(junban_list):
            if i == N-1:
                continue
            from_town = town
            to_town = junban_list[i+1]
            route += math.sqrt((from_town[0] - to_town[0])**2 + (from_town[1] - to_town[1])**2)
        sum_route += route
    
    print(sum_route / math.factorial(N))



if __name__ == "__main__":
    main()

Submission status: Accepted

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

m=0

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

print(m*2/n)

Submission status: Accepted

Solution code:
n = int(input())
x = [0]*n
y = [0]*n
for i in range(0,n):
    x[i], y[i] = input().split()
    x[i] = int(x[i])
    y[i] = int(y[i])
dist = 0
for i in range(0,n):
    for j in range(0,i):
        dist += ((x[i]-x[j])**2 + (y[i]-y[j])**2)**0.5

print(dist * 2 /n)

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
seq = []
for i in range(n):
    seq.append(i)
b = itertools.permutations(seq)
total = 0

for a in b:
    for i in range(1, n):
        total += math.sqrt((xy[a[i]][0] - xy[a[i-1]][0]) ** 2 +
                           (xy[a[i]][1] - xy[a[i-1]][1]) ** 2)
print(total/math.factorial(n))

Submission status: Accepted

Solution code:
# 2019/11/16

import sys
import itertools

sys.setrecursionlimit(10**7)
n=int(input())
xy=[]
for i in range(n):
    a,b=map(int,input().split())
    xy.append((a,b))

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

avg=0
for e in p:
    for i in range(n-1):
        avg+=pow((xy[e[i]][0]-xy[e[i+1]][0])**2+(xy[e[i]][1]-xy[e[i+1]][1])**2,0.5)
print(avg/len(p))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import numpy as np


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

diff = np.expand_dims(t, axis=1) - np.expand_dims(t, axis=0)
dis = np.sqrt(np.sum(diff ** 2, axis=-1))
#print(dis)
#print(dis.sum())
print(dis.sum()/N)

Submission status: Accepted

Solution code:
from itertools import permutations

import numpy as np

N = int(input())

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

combs = np.array(list(permutations(xys, N)))
ret = np.array(
    [np.linalg.norm(combs[:, i] - combs[:, i + 1], axis=1) for i in range(N - 1)]
).sum() / len(combs)

print("{:.10f}".format(ret))

Submission status: Accepted

Solution code:
import numpy as np
import itertools

N=int(input())

X=[]
Y=[]
for i in range(N):
    XY=input().split(" ")
    X.append(float(XY[0]))
    Y.append(float(XY[1]))

def get_dist(x1,y1,x2,y2):
    return np.sqrt(pow(x2-x1,2)+pow(y2-y1,2))

seq=range(1,N+1)
p=list(itertools.permutations(seq))

totals=[]
for i in range(len(p)):
    route=list(p[i])
    S=0
    for k in range(len(route)-1):
        S+=get_dist(X[route[k]-1],Y[route[k]-1],X[route[k+1]-1],Y[route[k+1]-1])
    totals.append(S)

print(np.average(totals))

Submission status: Accepted

Solution code:
import math
import itertools
import numpy as np
N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
d=np.zeros((N,N))
for i in range(N-1):
    for j in range(i+1,N):
        dd=math.sqrt((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)
        d[i,j]=dd
        d[j,i]=dd
ans=[]
path=list(itertools.permutations(range(N)))
for p in path:
    s=0
    for i in range(N-1):
        s+=d[p[i],p[i+1]]
    ans.append(s)
print(sum(ans)/len(ans))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
root = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for l in list(itertools.permutations(root)):
    total = 0
    for i in range(len(l) - 1):
        total += math.sqrt(((l[i][0] - l[i + 1][0]) ** 2) + ((l[i][1] - l[i + 1][1]) ** 2))
    ans += total
print(ans / math.factorial(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

N = int(input())
P = []
for i in range(N):
    P.append([int(a) for a in input().split()])

count = 0

for i in range(N):
    for j in range(N):
        if i < j:
            count += math.sqrt((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2)

print(2 * count / N)

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
x = []
y = []
for i in range(n):
  xy = input().split(" ")
  x.append(int(xy[0]))
  y.append(int(xy[1]))
sum_length = 0
for i in range(n-1):
  for j in range(i+1,n):
    sum_length += np.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)
print(sum_length*2/n)

Submission status: Accepted

Solution code:

import itertools
import math
N = int(input())
l = []
for i in range(N):
    a,b = map(int,input().split())
    l.append([a,b])


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

# print(len(t))
def cal(T):
    res = 0
    # print(T)
    for i,j in zip(T,T[1:]):
        res += math.sqrt(((l[i][0]-l[j][0])**2)+(l[i][1]-l[j][1])**2)
        # print(res)
    return res
ans = 0
s = 0
for A in t:
    ans += cal(A)
    s+=1
print(ans/s)

Submission status: Accepted

Solution code:
# ABC145 A
import itertools
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n = ni()
L = [[] for i in range(n)]
D = []
for i in range(n):
    x,y = nm()
    L[i].append(x)
    L[i].append(y)

L = list(itertools.permutations(L))

for l in L:
    d = 0.0
    for i in range(len(l)-1):
        d += float(((l[i][0]-l[i+1][0])**2 + (l[i][1]-l[i+1][1])**2)**0.5)
    D.append(d)

ans = float(sum(D)/len(D))
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
al = []
for _ in range(N):
    al.append(list(map(int,input().split())))
comb = 1
for i in range(1,N+1):
    comb *= i
combnum = comb//((N*(N-1))/2)
sumlen = 0
for i in range(N):
    for j in range(i,N):
        sumlen += math.sqrt((al[i][0]-al[j][0])**2+(al[i][1]-al[j][1])**2)*(combnum/N*2)

print(sumlen/combnum)

Submission status: Accepted

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

import itertools

seq = [i for i in range(N)]
seq2 = list(itertools.combinations(seq,2))

suml = 0

for i in range(len(seq2)):
    x = xy[seq2[i][0]][0] - xy[seq2[i][1]][0]
    y = xy[seq2[i][0]][1] - xy[seq2[i][1]][1]
    length = (x**2 + y**2)**0.5
    suml += length
    
print(suml*2/N)

Submission status: Accepted

Solution code:
import math
import itertools

n = int(raw_input())

pos = list()
for i in range(0, n):
    x, y = map(int, raw_input().split(" "))
    pos.append((x, y))

all_permutations = list(itertools.permutations(pos))
sum = 0.0
for x in all_permutations:
    length = len(x)
    tmp = 0.0
    for s in range(1,length):
        x_1, y_1 = x[s - 1]
        x_2, y_2 = x[s]
        dist = math.sqrt((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2)
        tmp = tmp + dist
    sum = sum + tmp

ans = sum / len(all_permutations)
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools

N = int(input())
x_y_list = [list(map(int,input().split()))for _ in range(N)]
distance_list = []
for i in range(N):
  for j in range(i+1,N,1):
    distance = math.sqrt((x_y_list[i][0]-x_y_list[j][0])**2 + 
                         (x_y_list[i][1]-x_y_list[j][1])**2)
    distance_list.append(distance)
ans = 0
c = list(itertools.combinations(distance_list,N-1))
for i in range(len(c)):
  ans += sum(c[i])
ans = ans/len(c)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import hypot
from itertools import permutations
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0

n=int(input())
li=list(range(n))
xy=[list(map(int,input().split())) for i in range(n)]
# ite=list(permutations(n,li／))
prr = list(permutations(li, n))
count=len(prr)
for pr in prr:
    for i in range(n-1):
        # print(hypot(xy[pr[i]][0]-xy[pr[i+1]][0],
        #             xy[pr[i]][1]-xy[pr[i]][1]), pr, i, xy[pr[i]][0]-xy[pr[i+1]][0],
        #       xy[pr[i]][1]-xy[pr[i]][1])
        # print(pr)
        ans += hypot(xy[pr[i]][0]-xy[pr[i+1]][0],
                        xy[pr[i]][1]-xy[pr[i+1]][1])
print(ans/count)


# for i in range(n):
#     for j in range(n):
#         if i==j:
#             continue
#         for k in range(n):
#             if i==k or j==k:
#                 continue
#             count+=1
#             ans += hypot(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
#             ans += hypot(xy[k][0]-xy[j][0], xy[k][1]-xy[j][1])

Submission status: Accepted

Solution code:
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

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

n = INT()
ll = [MAP() for _ in range(n)]

ans=0
for i in itertools.permutations(ll):
    for j in range(n-1):
        ans += dist(i[j],i[j+1])

print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import numpy as np
import math
N = int(input())
arr = [np.array(list(map(int,input().split()))) for _ in range(N)]
dist_arr = []
for i in range(N):
  for j in range(i+1,N):
    dist_arr.append(np.linalg.norm(arr[i]-arr[j]))

dist_arr = np.array(dist_arr)
dist_arr = dist_arr*(N-1)*2*(math.factorial(N-2))
print((dist_arr.sum())/math.factorial(N))

Submission status: Accepted

Solution code:
n=int(input())
XY=[list(map(int,input().split())) for _ in range(n)]
fact1,fact2=1,1
for i in range(1,n+1):
    fact1*=i
for i in range(1,n):
    fact2*=i
dist=0
for i in range(n):
    for j in range(i+1,n):
        dist+=((XY[i][0]-XY[j][0])**2+(XY[i][1]-XY[j][1])**2)**0.5
dist*=2*fact2
dist/=fact1
print(dist)

Submission status: Accepted

Solution code:
n = int(input())
location = []
import math
for _ in range(n):
    x,y  = map(int,input().split())
    location.append([x,y])
s = 0
for i in range(n):
    idex=i
    for j in range(n-1):
        idex +=1
        if idex>=n:
            idex=0
        v1 = abs(location[i][0]-location[idex][0])
        v2 = abs(location[i][1]-location[idex][1])
        v = math.sqrt((v1*v1)+(v2*v2))
        s += v*2
print(s/(2*n))

Submission status: Accepted

Solution code:
from scipy.spatial import distance

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

dist_mat = distance.cdist(points, points, metric='euclidean')

print(sum(sum(dist_mat))/N)

Submission status: Accepted

Solution code:
import math
n = int(input())
lst = [[int(j) for j in input().split()] for _ in range(n)]
ans = 0
for i in range(n):
    for j in range(n):
        if lst[i][0] == lst[j][0] and lst[i][1] == lst[j][1]:
            continue
        else:
            a = (lst[i][0] - lst[j][0]) ** 2 + (lst[i][1] - lst[j][1]) ** 2
        ans += math.sqrt(a)
print(ans / n)

Submission status: Accepted

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

print(sum(length)*2/n)

Submission status: Accepted

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

ans=0
for i in range(n-1):
    for j in range(n-1-i):
        x=(lis[i][0]-lis[n-1-j][0])**2
        y=(lis[i][1]-lis[n-1-j][1])**2
        l=(x+y)**0.5
        #print(l)
        ans+=l

ans=ans*2/n

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

print(2 * d / N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
N = int(input())
x = np.zeros(N)
y = np.zeros(N)
for i in range(N):
  x[i], y[i] = map(int, input().split())

sum = 0
for i in range(N):
  for j in range(i+1, N):
    sum += np.sqrt(np.square(x[i] - x[j]) + np.square(y[i] - y[j]))

print(sum*2/N)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools

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

ans=0
for i in range(n-1):
    for j in range(i+1,n):
        ans += math.sqrt((towns[i][0]-towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)

print(2*ans/n)

Submission status: Accepted

Solution code:
import itertools

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

for v in itertools.permutations(xy, N):
    p.append(v)

for i in range(len(p)):
    for j in range(N-1):
        cnt += ((p[i][j][0] - p[i][j+1][0])**2 + (p[i][j][1] - p[i][j+1][1])**2) ** 0.5

ans = cnt / len(p)

print(ans)

Submission status: Accepted

Solution code:
#C
import numpy as np
N = int(input())
P = np.array([input().split() for _ in range(N)], dtype=int)

LEN = np.zeros((N,N), dtype=float)

for i in range(N):
  for j in range(N):
    LEN[i,j] = sum((P[i] - P[j])**2)**0.5

rote = 0

# 探索経路の合計を返す
def getlen(before=(), after=()):
  if len(after) == 0:
    global rote
    rote += 1
    return sum([LEN[before[i], before[i+1]] for i in range(N-1)])
  t = 0
  for i in range(len(after)):
    t += getlen(before + (after[i],), after[:i] + after[i+1:])
  return t

t = getlen((), tuple(range(N)))

print(t / rote)

Submission status: Accepted

Solution code:
import itertools
import math
def dist(x1,y1,x2,y2):
    r = math.sqrt( (x1-x2)**2 + (y1-y2)**2 )
    return r

n = int(input())
r = [ list(map(int, input().split())) for i in range(n) ]
id = range(n)
idlst = list(itertools.permutations(id))
N = math.factorial(n)
distance = 0
for i in range(N):
    for j in range(1,n):
        pre = idlst[i][j-1]
        now = idlst[i][j]
        distance += dist(r[pre][0],r[pre][1],r[now][0],r[now][1])

ans = distance / N
print(ans)

Submission status: Accepted

Solution code:
import logging
import math

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

def main():
    N = int(input())
    L_2 = [list(map(int, input().split())) for _ in range(N)]
    logging.info("Hello!")

    logging.info(L_2)

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

    print('{:.10f}'.format(sum * 2 / N))
    
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

lst=[[0,0] for _ in range(N)]
for i in range(N):
  lst[i]=list(map(int,input().split()))
dist=[]
for i in range(N-1):
  for j in range(i+1,N):
    v=math.sqrt((lst[i][0]-lst[j][0])**2+(lst[i][1]-lst[j][1])**2)
    dist.append(v)
print(2*sum(dist)/N)

Submission status: Accepted

Solution code:
n = int(input())
pointx = []
pointy = []
for i in range(n):
    x, y = list(map(int, input().split()))
    pointx.append(x)
    pointy.append(y)


length = [[0]*n for _ in range(n)]
for i in range(n):
    for j in range(n):
        length[i][j] = ((pointx[i]-pointx[j])**2 + (pointy[i]-pointy[j])**2)**(1/2)

total = sum([sum([length[i][j] for i in range(n)]) for j in range(n) ])
print(total/(n**2-n)*(n-1))

Submission status: Accepted

Solution code:
N = int(input())


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

d_list = []
for i in range(N):
    for j in range(N):
        dx = x[i] - x[j]
        dy = y[i] - y[j]
        distance = (dx**2 + dy**2)**(0.5)
        d_list.append(distance)

print(sum(d_list)/N)

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
city = [[int(i) for i in input().split()] for j in range(n)]


allnum = math.factorial(n)

city_num = [int(i) for i in range(n)]

ans = 0

for v in itertools.permutations(city_num):
    # print(v)
    pre = -1
    for i in v:
        if pre == -1:
            pre = i
            continue
        ans += math.sqrt((city[i][0] - city[pre][0]) **
                         2 + (city[i][1] - city[pre][1]) ** 2)
        pre = i

print(ans/allnum)

Submission status: Accepted

Solution code:
N=int(input())
X =  [0] * N
Y =  [0] * N
for i in range(N):
    x,y = map(int,input().split())
    X[i] = x
    Y[i] = y
long = 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)**(1/2)
        long += l

ans = long*2/N
print(ans)

Submission status: Accepted

Solution code:
import math
N = int(input())
e = [[int(i) for i in input().split()] for i in range(N)]
ans = 0
count=0
for i in range(N):
    for j in range(i+1,N):
        ans += ((e[i][0]-e[j][0])**2+(e[i][1]-e[j][1])**2)**(1/2)
        count+=1
print(ans*2/N)

Submission status: Accepted

Solution code:
import itertools
import math
N = int(input())
x = [0 for i in range(N)]
y = [0 for i in range(N)]

for i in range(N):
    x[i], y[i] = map(int, input().split())
def fact(N):
    if N == 0:
        return 1
    return N * fact(N - 1)

total = 0
for p in itertools.permutations(range(N)):
    dis = 0
    for i in range(len(p) -1):
        dis += math.sqrt((x[p[i + 1]] - x[p[i]]) ** 2 + (y[p[i + 1]] - y[p[i]]) ** 2)
    total += dis
print(total / fact(N))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
c = []
for _ in range(n):
    x, y = map(int, input().split())
    c.append((x, y))

s = 0
for i in range(n):
    for j in range(n):
        xi, yi = c[i]
        xj, yj = c[j]
        d = np.sqrt((xi - xj)**2 + (yi - yj)**2)
        s += d
print(s / n)

Submission status: Accepted

Solution code:
import sys
import math
import itertools

def solve(n, p):
    s = 0
    patterns = list(itertools.permutations(range(n)))
    for pattern in patterns:
        # print(pattern)
        for i in range(n-1):
            s += math.sqrt((p[pattern[i]][0] - p[pattern[i+1]][0])**2 + (p[pattern[i]][1] - p[pattern[i+1]][1])**2)
    print(s / len(patterns))


if __name__ == '__main__':
    n = int(sys.stdin.readline().strip())
    p = []
    for _ in range(n):
        p.append(list((map(int, sys.stdin.readline().strip().split(" ")))))
    solve(n, p)

Submission status: Accepted

Solution code:
N = int(input())
XY = []
for i in range(N):
  tmp = [int(i) for i in input().split()]
  XY.append(tmp)

result = 0

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

    result += dis

print((result * 2)/N)

Submission status: Accepted

Solution code:
import sys
import itertools as it
from collections import defaultdict
sys.setrecursionlimit(10**6)
# input = sys.stdin.readline
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    N=ii()
    x=[]
    y=[]
    dec=defaultdict(list)
    dec_sum=0
    dec_ave=0
    cnt=0
    for i in range(N):
        X,Y=mis()
        x.append(X)
        y.append(Y)
    for i in range(N):
        for j in range(N):
            dec[i].append(((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5)
    for ll in it.permutations(range(N)):
        now=ll[0]
        cnt+=1
        for i in ll[1:]:
            dec_sum+=dec[now][i]
            now=i
    print(dec_sum/cnt)

    


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import permutations
from sys import stdin


def main():
    N = int(stdin.readline().rstrip())
    xys = [[int(i) for i in stdin.readline().rstrip().split()] for _ in range(N)]
    perm = list(permutations(range(N)))
    results = []
    for points in perm:
        dis = 0
        for i, point in enumerate(points[:-1]):
            p1 = point
            p2 = points[i + 1]
            x1, y1 = xys[p1]
            x2, y2 = xys[p2]
            dis += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
        results.append(dis)
    print(sum(results) / len(results))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:


import sys
from collections import deque, defaultdict
import copy
import bisect
sys.setrecursionlimit(10 ** 9)
import math
import heapq
from itertools import product, permutations,combinations
import fractions
from operator import itemgetter


import sys
def input():
	return sys.stdin.readline().strip()

N = int(input())

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

towns = [i for i in range(N)]

keiros = list(permutations(towns))

sum = 0

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


for keiro in keiros:
	total = 0
	for i in range(N - 1):

		A = XY[keiro[i]]
		B = XY[keiro[i + 1]]
		total += dist(A, B)
	sum += total



def fact(n, mod=1000000007):
	ans = 1
	for i in range(n):
		ans *= i + 1
		if mod != 0 and ans >= mod:
			ans = ans % mod
	return ans

sum /= fact(N)

print(sum)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
List=[list(map(int,input().split())) for i in range(N)]
roots = list(itertools.permutations(range(N)))
sum_length = 0
for root in roots:
    first_city = 100 # 存在しない
    for city in root:
        if first_city == 100:
            first_city = city
            continue
        x = List[first_city][0] - List[city][0]
        y = List[first_city][1] - List[city][1]
        sum_length += math.sqrt(pow(x,2)+pow(y,2))
print(sum_length/len(roots))

Submission status: Accepted

Solution code:
import itertools
import math

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

rootlis = list(itertools.permutations(dislis))

dis = 0
for lis in rootlis:
    for j in range(n-1):
        dis += ((int(lis[j][0])-int(lis[j+1][0])) ** 2 + (int(lis[j][1])-int(lis[j+1][1])) ** 2) ** (1/2)


print(str(dis/math.factorial(n)))