Problem:


Score : 300 points

Problem Statement

There are N towns in a coordinate plane. Town i is located at coordinates (x_i, y_i). The distance between Town i and Town j is \sqrt{\left(x_i-x_j\right)^2+\left(y_i-y_j\right)^2}.

There are N! possible paths to visit all of these towns once. Let the length of a path be the distance covered when we start at the first town in the path, visit the second, third, \dots, towns, and arrive at the last town (assume that we travel in a straight line from a town to another). Compute the average length of these N! paths.

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

\left(x_i, y_i\right) \neq \left(x_j, y_j\right) (if i \neq j)

(Added 21:12 JST) All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

Print the average length of the paths.
Your output will be judges as correct when the absolute difference from the judge's output is at most 10^{-6}.

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

There are six paths to visit the towns: 1 → 2 → 3, 1 → 3 → 2, 2 → 1 → 3, 2 → 3 → 1, 3 → 1 → 2, and 3 → 2 → 1.

The length of the path 1 → 2 → 3 is \sqrt{\left(0-1\right)^2+\left(0-0\right)^2} + \sqrt{\left(1-0\right)^2+\left(0-1\right)^2} = 1+\sqrt{2}.

By calculating the lengths of the other paths in this way, we see that the average length of all routes is:

\frac{\left(1+\sqrt{2}\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)+\left(2\right)+\left(1+\sqrt{2}\right)}{6} = 2.276142...

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

There are two paths to visit the towns: 1 → 2 and 2 → 1. These paths have the same length.

Sample Input 3

8
-406 10
512 859
494 362
-955 -475
128 553
-986 -885
763 77
449 310

Sample Output 3

7641.9817824387



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Accepted

Solution code:
import numpy as np
input1 = list(map(int,input().split()))

N = input1[0]

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


distance = 0

for i in range(N):
  for j in range(i,N):
    distance += np.sqrt((input2[i][0] - input2[j][0])**2 + (input2[i][1] - input2[j][1])**2)

ans = 2*distance/N
print(ans)

Submission status: Accepted

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

p = itertools.permutations(pos,n)
ans = 0
for l in p:
    for i in range(n-1):
            ans += ((l[i][0]-l[i+1][0])**2 + (l[i][1]-l[i+1][1])**2)**0.5
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import itertools
import math

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

town_routes = len(list(itertools.permutations(town_xy)))

sum_distance = 0
for route in itertools.permutations(town_xy):
    for i in range(1, len(route)):
        x_diff = route[i-1][0] - route[i][0]
        y_diff = route[i-1][1] - route[i][1]
        sum_distance += math.sqrt(x_diff**2 + y_diff**2)

print(sum_distance/town_routes)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
s=int(input())
t=[list(map(int,input().split())) for i in range(s)]
list=[]
for i in range(s):
  for j in range(s):
    a=math.sqrt((t[i][0]-t[j][0])**2+(t[i][1]-t[j][1])**2)
    list.append(a)
c=1
for l in range(s):
  c*=(l+1)
e=c
c=c//s
d=0
for p in range(len(list)):
  d+=list[p]
d=d*c
d=d/e
print(d)

Submission status: Accepted

Solution code:
n = int(input())
import math
import numpy as np
xy = []
for i in range(n):
    array = list(map(int, input().split()))
    xy.append(array)


def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
l = []

k=0
for i in range(0,n-1):
	for j in range(i+1,n):
		
		l.append(math.sqrt((xy[i][0] -xy[j][0])**2 + (xy[i][1] - xy[j][1])**2))
		
		k += 1
print
a = (n-1) * math.factorial(3)/k
l_sum = np.sum(np.array(l) *a)

print(l_sum/math.factorial(3))

Submission status: Accepted

Solution code:
import itertools
import math

num = int(input())
town_list = [[int(item) for item in input().split()] for _ in range(num)]

root_list = list(itertools.permutations(list(range(num))))

length = 0

for root in root_list:
    for i in range(num-1):
        temp_path = root[i:i+2]
        first = temp_path[0]
        second = temp_path[1]

        x_length = town_list[first][0] - town_list[second][0]
        y_length = town_list[first][1] - town_list[second][1]


        length += math.sqrt(x_length**2 + y_length**2)
print(length / len(root_list))

Submission status: Accepted

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


def main():
    sc = Scan()
    n = sc.intarr()[0]
    array = []
    for i in range(n):
        array.append(sc.intarr())
    d_sum = 0
    for i in range(len(array)):
        for j in range(i+1, len(array)):
            distance = math.sqrt(
                (array[i][0] - array[j][0])**2 + (array[i][1] - array[j][1])**2)
            d_sum += distance
    comb = math.factorial(n) // (math.factorial(n - 2) * math.factorial(2))
    ans = d_sum * (n-1) / comb

    print(ans)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
fac = math.factorial(n-1)

ll = [i for i in range(0, n)]
con = list(itertools.combinations(ll, 2))
cnt = len(con)

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

ans = []
for i, j in con:
    ans.append(((ls[i][0] - ls[j][0])**2 + (ls[i][1]-ls[j][1])**2)**0.5)

print(sum(ans)/(n/2))

Submission status: Accepted

Solution code:
import math
N=int(input())
x=[]
y=[]
M=0
for i in range(0,N):
    F=input()
    [v,s]=list(map(int,F.split(' ')))
    x.append(v)
    y.append(s)
def dis(x,y,x2,y2):
    return math.sqrt((x-x2)**2+(y-y2)**2)
for i in range(0,N):
    for j in range(0,N):
        M=M+dis(x[i],y[i],x[j],y[j])
print(M/N)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
x = [input().split(" ") for j in range(N)]
ite = [i for i in range(N)]
iterter = list(itertools.permutations(ite,N))

ans = 0
fact = math.factorial(N)

for i in iterter:
    for j in range(len(i) - 1):
        tmp = math.sqrt(((int(x[i[j]][0]) - int(x[i[j + 1]][0])) ** 2) + ((int(x[i[j]][1]) - int(x[i[j + 1]][1]))**2))
        ans += tmp
    
print(ans / fact)

Submission status: Accepted

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

import math
import itertools

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

if (N>2):
  ali =[]
  for i in itertools.permutations(XY,N):
    for j in range(N-1):
      ali.append(math.sqrt(((i[j][0] - i[j+1][0])**2)+((i[j][1] - i[j+1][1])**2)))
  print(sum(ali)/math.factorial(N))
else:
  ali = []
  for i in itertools.permutations(XY,2):
    ali.append(math.sqrt(((i[0][0] - i[1][0])**2)+((i[0][1] - i[1][1])**2)))
  print(sum(ali)/math.factorial(N))

Submission status: Accepted

Solution code:
from math import sqrt 


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

Submission status: Accepted

Solution code:
import math
import itertools

# 引数のリストの全ての順列リストを返す
def fact_list(seq:list):
    return list(itertools.permutations(seq))

# n!を返す
def fact_num(n:int):
    seq = list(range(n))
    return len(fact_list(seq))

N = int(input())
n_fact_list = fact_list(list(range(N)))
n_fact_num = fact_num(N)
x, y = [], []
for i in range(N):
    xi, yi = map(int, input().split())
    x.append(xi)
    y.append(yi)

d = 0
for order in n_fact_list:
    for idx, i in enumerate(order[:-1]):
        j = order[idx+1]
        d += (math.sqrt( (x[i]-x[j])**2 + (y[i]-y[j])**2 ))
print(d/n_fact_num)

Submission status: Accepted

Solution code:
from itertools import combinations, permutations
from math import factorial
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    XY = [tuple(map(int, input().split())) for _ in [0] * N]

    n = list(range(N))
    dist = [[0] * N for _ in [0] * N]
    for i, j in combinations(n, 2):
        dist[i][j] = ((XY[i][0] - XY[j][0]) ** 2 + (XY[i][1] - XY[j][1]) ** 2) ** 0.5
        dist[j][i] = dist[i][j]

    ans = 0
    for r in permutations(n):
        for i in range(N - 1):
            ans += dist[r[i]][r[i+1]]
    print(ans / factorial(N))


main()

Submission status: Accepted

Solution code:
if __name__=='__main__':
    n = int(input())
    x = ['' for i in range(n)]
    y = ['' for i in range(n)]
    length = 0.0
    for i in range(n):
        x[i],y[i]=map(int,input().split())
    for i in range(n-1):
        for j in range(i+1,n):
            length += pow( (x[i]-x[j])**2+(y[i]-y[j])**2, 0.5)
    print(length*2.0/n)

Submission status: Accepted

Solution code:
import math

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

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

dup = 1
for i in range(n-2):
  if dup == 0:
    dup = 1
  dup *= (i+1)

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

av = tlen / tcase * (dup * (n-1))
print(av)

Submission status: Accepted

Solution code:
import itertools
import math

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

x,y = [],[]
n = int(input())
for val in range(n):
    x_tmp,y_tmp = map(int,input().split())
    x.append(x_tmp)
    y.append(y_tmp)

comb = list(itertools.combinations(range(n), 2))
zyun = list(itertools.permutations(range(n)))
distance_L = {}

# あらかじめ2転換を計算
for val in comb:
    tenkan = list(sorted(list(val)))
    a = [x[val[0]],y[val[0]]]
    b = [x[val[1]],y[val[1]]]
    
    distance_L[val] = euclid(a,b)

ans = 0
counter = 0

for i in zyun:
    for j in range(n-1):
        tmp = tuple(sorted(i[j:j+2]))
        #print(tmp)
        ans += distance_L[tmp]
    counter += 1

print(ans/counter)

Submission status: Accepted

Solution code:
def dist(x1, y1, x2, y2):
    return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5

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

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

ans = ans * 2 / N

print(ans)

Submission status: Accepted

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

A = []

for i in range(N):
    tmpx, tmpy = map(int, input().split())
    A.append([tmpx,tmpy])

d = []

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

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

com *= 2

ans = 0
for i in range(len(d)):
    ans += d[i]*com

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

print(ans/M)

Submission status: Accepted

Solution code:
import math
N=int(input())
List=[list(map(int,input().split())) for i in range(N)]
V=[]
for idx in range(N):
    a=List[idx]
    for idy in range(N):
        if idx == idy:
            continue
        b=List[idy]
        V.append(pow(pow(a[0]-b[0],2) + pow(a[1]-b[1], 2), 1/2))
sum=0
pattern=math.factorial(N)
for i in V:
    sum += i * int(pattern/N)
print(sum/pattern)

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

kumi = [x for x in range(N)]

def kyori(x1,y1,x2,y2):
    return math.sqrt((y2 - y1)**2 + (x2 - x1)**2)
sum_kyori = 0.0
for i in itertools.permutations(kumi):
    for j in range(N-1):
        sum_kyori += kyori(x[i[j]],y[i[j]],x[i[j+1]],y[i[j+1]])
print( sum_kyori/math.factorial(N))

Submission status: Accepted

Solution code:
import math


class point():
    def __init__(self, x,y):
        self.x = x
        self.y = y



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


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

Submission status: Accepted

Solution code:
import math

n = int(input())
a=[]

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

def dist(i,j):
    b = ((a[i][1]-a[j][1])**2+(a[i][0]-a[j][0])**2)**0.5
    if b<0:
        print("false")
    return b

sum=0
for i in range(n):
    for j in range(n):
        if j==i:
            pass
        else:
            sum += dist(i,j)

print(sum*math.factorial(n-1)/math.factorial(n))

Submission status: Accepted

Solution code:
from itertools import combinations, permutations
import math
N = int(input())
cor = []
for n in range(N):
    X, Y = map(int, input().split())
    cor.append((X, Y))

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

ans = 0
for item in list(permutations([i for i in range(N)], N)):
    for j in range(len(item) - 1):
        ans += dist[item[j]][item[j + 1]]
print(ans / math.factorial(N))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

a = math.factorial(N)
b = a * 2 / N
ans = 0
for i in range(N-1):
    for j in range(i,N):
        m = ((X[i]-X[j])**2 + (Y[i]-Y[j])**2) ** (1/2)
        n = b * m
        ans += n
print(ans/a)

Submission status: Accepted

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

for i in range(n):
    for j in range(n):
        if i == j:
            continue
        else:
            isum += math.factorial(n-1)*math.sqrt((z[i][0] - z[j][0])*(z[i][0] - z[j][0]) + (z[i][1] - z[j][1])*(z[i][1] - z[j][1]))
            #print(i,j,isum)

print(isum/math.factorial(n))

Submission status: Accepted

Solution code:
import math
import copy

n=int(input())
originmap=[] #appendのために宣言が必要
while True:
    try:
        originmap.append(list(map(int,input().split())))

    except:
        break;
        #または、quit(),os.exit()をして止める。

length = 0
submap = originmap.copy()
for i,j in originmap:
  del submap[0]
  for a, b in submap:
    #print(submap)
    #print(i,j,a,b)
    length += math.sqrt((i-a)**2 + (j-b)**2)

print(length*2/n)

Submission status: Accepted

Solution code:
from math import factorial

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())
ans = 0
cnt = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += ((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2) ** 0.5
        cnt += 1
print(ans  * (N - 1) / cnt )

Submission status: Accepted

Solution code:
def A():
    print(int(input())**2)

def B():
    length = int(input())
    s = str(input())
    if length%2 != 0 or s[:length//2]!=s[length//2:]:
        print('No')
    else:
        print('Yes')

import math
def C():
    length = int(input())
    coords = []
    for i in range(length):
        coords.append([int(k) for k in input().split()])
    def dist(p1, p2):
        return math.sqrt((p2[0]-p1[0])**2+(p2[1]-p1[1])**2)

    distances = []
    for i in range(length):
        for j in range(i+1, length):
            distances.append(dist(coords[i], coords[j]))
    #2 for ex1, 0 for ex2
    # a, b, c, d
    # ab, ac, ad, bc, bd, cd
    m = length*(length-1)/2
    print(sum(distances)/m*(length-1))

C()

Submission status: Accepted

Solution code:
import math
import itertools
n = int(input())
x = []
y = []
p = []
seq = []
for i in range(n):
    a,b = map(float,input().split())
    x.append(a)
    y.append(b)
    seq.append(i)
p = list(itertools.permutations(seq))
li = []
for s in p:
    l = 0.0
    for i in range(n-1):
        l += math.sqrt((x[s[i]] - x[s[i+1]]) ** 2 + (y[s[i]] - y[s[i+1]]) ** 2)
    li.append(l)
print(sum(li) / len(p))

Submission status: Accepted

Solution code:
import math, itertools
n = int(input())
def d(a, b):
  return math.sqrt(((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2))
lst = []
for i in range(n):
  x, y = map(int, input().split())
  lst.append([x, y])
ans = 0
for v in itertools.permutations(lst, 2):
  ans += d(v[0], v[1])
print(ans/n)

Submission status: Accepted

Solution code:
import itertools

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

ret = []
for l in itertools.permutations(list(range(n))):
    tmp = 0
    for i in range(len(l)-1):
        j = l[i]
        k = l[i+1]
        tmp += (((xl[j] - xl[k]) ** 2) + ((yl[j] - yl[k]) ** 2)) ** 0.5
    ret.append(tmp)
print(sum(ret)/len(ret))

Submission status: Accepted

Solution code:
N = int(input())
x = [0]*N
y = [0]*N
z = [0]*N
for i in range(0,N):
    z[i] = list(map(int, input().split()))
    x[i] = z[i][0]
    y[i] = z[i][1]
sum = 0
for i in range(0,N-1):
    for j in range(i+1,N):
        sum = sum + ((x[i]-x[j])**2+(y[i]-y[j])**2)**(1/2)
ans = sum*2 / N
print(ans)

Submission status: Accepted

Solution code:
import itertools
from math import factorial

n = int(input())
p = [tuple(map(int, input().split())) for _ in range(n)]
d = list()
for pp in itertools.combinations(p, 2):
    d.append(((pp[0][0] - pp[1][0])**2 + (pp[0][1] - pp[1][1])**2)**0.5)
f = factorial(n)
i = f * (n-1) / len(d)
print(sum(d) * i / f)

Submission status: Accepted

Solution code:
N = int(input())

xList = []
yList = []

for i in range(N):
    x, y = map(int, input().split())
    xList.append(x)
    yList.append(y)

xsum = sum(xList)
ysum = sum(yList)

sum = 0
for i in range(N):
    isum = 0
    for j in range(N):
        length = ((xList[i]-xList[j])**2 + (yList[i]-yList[j])**2)**0.5
        isum += length
    isum /= N
    sum += isum



print(sum)

Submission status: Accepted

Solution code:
import math

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


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

summation = 0
for i in range(n):

    for j in range(i+1, n):
        d = dist(L[i], L[j])
        
        summation += d

print(summation * 2 / n)

Submission status: Accepted

Solution code:
import math as ma

n = int(input())
m = [list(map(int, input().split())) for i in range(n)]
t = [[0 for j in range(n) ] for i in range(n)]
f = [0 for _ in range(n)]
ans = 0

for i in range(n):
    for j in range(n):
        if i == j or t[i][j] > 0:
            pass
        else:
            x = m[i][0] - m[j][0]
            y = m[i][1] - m[j][1]
            l = x**2 + y**2
            t[i][j] = ma.sqrt(l)
            t[j][i] = ma.sqrt(l)
        #     print('l',l)
        # print('aa',m,t,f)

for i in range(n):
    ans += sum(t[i])

print(ans/n)

Submission status: Accepted

Solution code:
import numpy as np
import itertools
import math
N = int(input())

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

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

dist = np.zeros([N, N])
for i in range(N):
    for j in range(N):
        dist[i,j] = np.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

perm = list(itertools.permutations(range(N)))
num = math.factorial(N)
sum = 0
for i in perm:
    for j in range(len(i)-1):
        sum += dist[i[j], i[j+1]]
print(sum/num)

Submission status: Accepted

Solution code:
import numpy as np
import math
import itertools

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 v in itertools.permutations(np.arange(n), n):
    for i, j in enumerate(v):
        if i == 0:
            pass
        else:
            sum_ += math.sqrt((x[v[i]]-x[v[i-1]])*(x[v[i]]-x[v[i-1]]) + (y[v[i]]-y[v[i-1]])*(y[v[i]]-y[v[i-1]])) 
    # print(v)
    # print(sum_)

print(sum_ / math.factorial(n))

# (0, 1, 2)
# (0, 2, 1)
# (1, 0, 2)
# (1, 2, 0)
# (2, 0, 1)
# (2, 1, 0)

Submission status: Accepted

Solution code:
import math

n = int(input())
lis = [0]*n
for i in range(n):
  x,y = map(float,input().split())
  lis[i] = [x,y]
ans = 0
for i in range(n):
  for j in range(i+1,n):
    ans += ((lis[i][0]-lis[j][0])**2+(lis[i][1]-lis[j][1])**2)**0.5

a = 2*ans/n
print(a)

Submission status: Accepted

Solution code:
N=int(input())
L=[]
for i in range(N):
  L.append(list(map(int,input().split())))
def distance(a,b):
  import math
  return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
dist=0
for i in range(N-1):
  for j in range(i+1,N):
    dist+=distance(L[i],L[j])
if N==2:
  print(dist)
else:
  print(dist*2/N)

Submission status: Accepted

Solution code:
import math
n = int(input())  
x = [0] * n
y = [0] * n
for i in range(0,n):
    # print(i,c,s[i:i+1],x)
    (x[i],y[i]) = map(int,input().split())  
    # print(x[i],y[i]) 

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

av = float(sum) / ( n / 2 )
print(av)

Submission status: Accepted

Solution code:
import math

n = int(input())
a = math.factorial(n)
b = (a*(n-1))/(n*(n-1)/2)
l=0

x_list = []
y_list = []

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

for j in range(n):
    for k in range(n):
        if j>=k:
            continue
        l += math.sqrt((x_list[j]-x_list[k])**2+(y_list[j]-y_list[k])**2)

print(l*b/a)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

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

ave = 0
jun = permutations(range(n))
for j in jun:
    #print(j)
    sm = 0
    for i in range(n-1):
        x, y = xy[j[i]]
        nx, ny = xy[j[i+1]]
        #print(x, y, nx, ny)
        sm += ((x-nx)**2 + (y-ny)**2)**0.5
    ave += sm
print(ave/factorial(n))

Submission status: Accepted

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

m = 1
for i in range(1, n+1):
    m *= i
total = 0
for p in itertools.permutations(list(range(n)), n):
    for i in range(1, n):
        total += ((xy[p[i]][0] - xy[p[i-1]][0]) ** 2 + (xy[p[i-1]][1] - xy[p[i]][1]) ** 2) ** 0.5
print(total / m)

Submission status: Accepted

Solution code:
import os, sys, re, math

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

s = 0
for i in range(N):
    for j in range(N):
        if i != j:
            tmp = (root[i][0] - root[j][0]) ** 2 + (root[i][1] - root[j][1]) ** 2
            s += math.sqrt(tmp)

ret = s / N
print(ret)

Submission status: Accepted

Solution code:
import sys
import math

def main():
  N = int(input())
  x = [0] * N
  y = [0] * N
  for i in range(N):
    x[i], y[i] = map(lambda j: int(j), input().split(' '))
  total = 0
  for i in range(N):
    for j in range(N):
      distance = math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
      total += distance
  print(total / N)

main()

Submission status: Accepted

Solution code:
import math
# import numpy as np
import itertools
N = int(input())
x = []
y = []
for i in range(N):
    s1,s2 = map(int,input().split())
    x.append(s1)
    y.append(s2)
    
def length(i,j):
    return math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

LI = [i for i in range(N)]
A = list(itertools.permutations(LI))
ans = 0
for item in A:
#     print(item)
    count = 0
    for i in range(len(item)):
        if i == len(item)-1:
            break
#         print(length(item[count],item[count+1]))
        ans = ans+length(item[count],item[count+1])
        count +=1
print(ans/math.factorial(N))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import math
import itertools
def distance(N, ar):
    table = [[0] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if i != j:
                dx = ar[i][0] - ar[j][0]
                dy = ar[i][1] - ar[j][1]
                table[i][j] = math.sqrt(dx * dx + dy * dy)
    return table    

def print_ans(N, ar):
    """Test Case
    >>> print_ans(3, [[0, 0],[1, 0],[0, 1]])
    2.2761423749
    >>> print_ans(2, [[-879, 981], [-866, 890]])
    91.9238815543
    >>> print_ans(8, [[-406, 10],[512, 859],[494, 362],[-955, -475],[128, 553],[-986, -885],[763, 77],[449, 310]])
    7641.9817824387
    """
    fac = math.factorial(N)
    perm_list = list(itertools.permutations(range(N) ) )
    table = distance(N, ar)
    dist = 0
    for perm in perm_list:
        for i in range(len(perm) -1):
            dist += table[perm[i]][perm[i+1]]
    print(dist/fac)


if __name__ == '__main__':
    N = int(input().rstrip())
    ar = [list(map(int, input().rstrip().split())) for _ in range(N)]
    print_ans(N, ar)

Submission status: Accepted

Solution code:
import numpy as np
import math
N = int(input())
L = []
for _ in range(N):
    temp = list(map(int,input().split()))
    L.append(np.array(temp))
A = []
for i in range(N-1):
    for j in range(i+1,N):
        u = L[i] - L[j]
        A.append(2*math.factorial(N-1)*(np.linalg.norm(u)))
A = np.array(A)
print(np.sum(A)/math.factorial(N))

Submission status: Accepted

Solution code:
n = int(input())
x = list()
y = list()
l = 0
t = 0

for i in range(n):
    m = list(map(int,input().split()))
    x.append(m[0])
    y.append(m[1])
    
for i in range(n - 1):
    for j in range(n - 1 - i):
        l_0 = (((x[i] - x[j + i + 1]) ** 2) + ((y[i] - y[j + i + 1]) ** 2)) ** (1 / 2)
        l += l_0

for i in range(n - 1):
    t += i + 1
    
print((n - 1) * l / t)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
li = [list(map(int, input().split())) for i in range(n)]
li_p = list(itertools.permutations(li, n))
li_a = []
for x in li_p:
  a = 0
  for i in range(n-1):
    a += ((x[i][0]-x[i+1][0])**2 + (x[i][1]-x[i+1][1])**2)**(1/2)
  li_a.append(a)
print(sum(li_a)/len(li_a))

Submission status: Accepted

Solution code:
import math

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

for i in range(N):
  List.append(list(map(int,input().split())))
  
tot = 0

for m in range(N):
  for n in range(N):
    tot += math.sqrt((List[m][0]-List[n][0])**2+(List[m][1]-List[n][1])**2)

print(tot/N)

Submission status: Accepted

Solution code:
import math
def cal(x1, y1, x2, y2):
    return math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

N = int(input())
x = []
y = []
for i in range(N):
    tempx, tempy = map(int,input().split())
    x.append(tempx)
    y.append(tempy)
acc = 0
kaijou = 1
#N*(N-1)/2通りの経路パターン
for i in range(1, N+1):
    kaijou *= i
num_use = kaijou*(N-1) / (N*(N-1)/2)
for i in range(N):
    for j in range(i+1, N):
        val = cal(x[i], y[i], x[j], y[j])
        acc += val*num_use
print(str(acc/kaijou))

Submission status: Accepted

Solution code:
num = int(input())

x = [0]*num
y = [0]*num

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

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

sol = [0]*sol_n

sum_l = 0.0

for n in range(num):
    for m in range(num):
        if(n != m):
            sum_l += ((x[n] - x[m])**2 + (y[n] - y[m])**2)**(1/2)
print(sum_l / (num))

Submission status: Accepted

Solution code:
#!python3.4.3
import math


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

    for i in range(n):
        pos.append(list(map(int, input().split(' '))))
    
    sum_ = 0
    for i in range(n):
        first = pos[i]
        for j in range(n):
            if j == i:
                continue
            x = (first[0] - pos[j][0])**2
            y = (first[1] - pos[j][1])**2
            d = (x + y)**0.5
            sum_ += d
    print(sum_/n)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
import itertools as it
n = int(input())
x = []
y = []
for _ in range(n):
    a, b = input().split(' ')
    x.append(int(a))
    y.append(int(b))


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


n_l = list(range(n))

l = list(it.permutations(n_l))

count = 0

for i in set(l):
    i = list(i)
    for j in range(n - 1):
        a = i[j]
        b = i[j + 1]
        count += f(x[a], x[b], y[a], y[b])

print(count / len(l))

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi, factorial
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    xxyy = [tuple(map(int, input().split())) for _ in range(N)]
    ssum = 0
    for a,b in combinations(xxyy,2):
        #print(a,b) 
        dx = (a[0] - b[0])**2
        dy = (a[1] - b[1])**2
        tmp = sqrt(dx+dy)
        #print(tmp)
        ssum += tmp
    #print("---")
    #print(ssum)
    print(ssum*2/N)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

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

n = int(input())
#print(n)
point=[] 
while True:
    try:
        point.append(list(map(int,input().split())))
    except:
        break;

#print(point)
kyori = 0
for i in range(n):
	for j in range(n):
		if(i!=j):
			kyori += dist(point[i],point[j])

print(kyori/n)

Submission status: Accepted

Solution code:
import math

n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
# print(xy)
sum = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        sum += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
# print(sum)

k = sum * 2 * (n - 1) / math.factorial(n)
# k = sum * math.factorial(n - 1) / n
print(sum*2/n)

Submission status: Accepted

Solution code:

import itertools

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

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



route_list = list(itertools.permutations(map_list, n))

dist_sum = 0

for route in route_list:
    for i in range(n-1):
        dist = detect_dist(route[i], route[i+1])
        dist_sum += dist

print(dist_sum/len(route_list))