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 math

N = int(input())

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

total = 0

for i in range(N):
    for j in range(N):
        if i != j:
            total += math.sqrt((L[i][0]-L[j][0])**2 + (L[i][1]-L[j][1])**2)
 
print(total/N)

Submission status: Accepted

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

m=0

for i in range(N):
    for p in range(N):
        m+=((l[i][0]-l[p][0])**2+(l[i][1]-l[p][1])**2)**(1/2)
print(m/N)

Submission status: Accepted

Solution code:
from math import sqrt
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


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


for i in range(N):
    for j in range(i, N):
        ans += dist(L[i], L[j])

print(ans*2/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 = 0

for j in range(n):
    for k in range(n):
        dist += math.sqrt(((x[j] - x[k])**2) +  ((y[j] - y[k])**2))
        
fac = math.factorial(n)
kaz = n * (n-1) / 2

bas = dist / 2
print (bas * (n-1) / kaz )

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
import math
import itertools
row_length = int(input())
point = {}
for i in range(row_length):
    point[i] = list(map(int, input().split()))
point_list = [point[x] for x in range(len(point))]
pattern_list = list(itertools.permutations(point_list))



def calc_dist(pat_list): #旅程リストを入れた時に、その距離を計算する
    dist = 0
    for i in range(len(pat_list)-1):
        dist += math.sqrt(pow(pat_list[i][0] - pat_list[i+1][0], 2) + pow(pat_list[i][1] - pat_list[i+1][1], 2))
    return dist

ans_dist = 0
for j_list in pattern_list:
    ans_dist += calc_dist(j_list)

print(ans_dist/len(pattern_list))

Submission status: Accepted

Solution code:
n = int(input())

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

# print(xy)

import itertools
import numpy as np

def calc_distance(z1,z2):
    v1 = np.array(z1)
    v2 = np.array(z2)
    d = np.linalg.norm(v1-v2,2)
    return d


table = np.zeros((n,n))
for i in range(n):
    for j in range(n):
        if i==j:
            pass
        else:
            z1 = xy[i]
            z2 = xy[j]
            table[i,j] = calc_distance(z1,z2)
        
    
# print(table)

wa = 0
count = 0
for i in itertools.permutations(range(1,n+1)):
    # print(i)
    count += 1
    for j in range(len(i)-1):
        d = table[i[j]-1,i[j+1]-1]
        # print(d)
        wa += d

ans = wa/count
# print(wa)
# print(count)
print(ans)

Submission status: Accepted

Solution code:
from math import sqrt
from itertools import combinations
N=int(input())
XY=[list(map(int, input().split())) for _ in range(N)]
print((N-1)*sum(map(lambda z: sqrt((z[0][0]-z[1][0])**2+(z[0][1]-z[1][1])**2), combinations(XY,2)))/len(list(combinations(XY,2))))

Submission status: Accepted

Solution code:
import sys
import itertools


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    xy = [list(map(int, readline().split())) for _ in range(n)]
    mt = 0
    cnt = 0
    for v in itertools.permutations([i for i in range(n)], n):
        cnt += 1
        for i in range(1, n):
            mt += ((xy[v[i]][0] - xy[v[i-1]][0]) ** 2 + (xy[v[i]][1] - xy[v[i-1]][1]) ** 2) ** 0.5
    print(mt / cnt)


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

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

    # calc


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools

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


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

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

candidate = list(itertools.permutations(base, N))

ans = 0
for i in candidate:
        tmp = 0
        for j in range(len(i) - 1):
                tmp += calc_distance(point[i[j]], point[i[j+1]])
        ans += tmp

print(ans / len(candidate))

Submission status: Accepted

Solution code:
import math

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

def dist(x_1, y_1, x_2, y_2):
  return math.sqrt((x_2 - x_1)**2 + (y_2 - y_1)**2)

for i in range(n):
  for j in range(i, n):
    sum += dist(xy[i][0], xy[i][1], xy[j][0], xy[j][1])

print(sum*2/n)

Submission status: Accepted

Solution code:
import numpy as np

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

all_diffs = np.expand_dims(X, axis=1) - np.expand_dims(X, axis=0)
distance_matrix = np.sqrt(np.sum(all_diffs**2, axis=-1))
distance = np.sum(distance_matrix) / N

print(distance)

Submission status: Accepted

Solution code:
N=int(input())

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

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2)**0.5

print(k/N)

Submission status: Accepted

Solution code:
import math

a = int(input())
x = []
y = []
total_dis = 0
count = 0
for i in range(a):
  n, m = map(int, input().split())
  x.append(n)
  y.append(m)

for i in range(a):
  x_1 = x[i]
  y_1 = y[i]
  for j in range(a):
    dis = math.sqrt((x_1 - x[j])**2 + (y_1 - y[j])**2)
    count += 1
    total_dis += dis


print(total_dis/(count/a))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    return


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

    num = 0
    ans = 0
    l = list(range(N))
    for p in permutations(l):
        num += 1

        for i in range(1, len(p)):
            ans += sqrt((points[p[i - 1]][0] - points[p[i]][0]) ** 2 + (points[p[i - 1]][1] - points[p[i]][1]) ** 2)

    print(ans / num)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
import sys
from math import sqrt, factorial
from itertools import permutations

def _i(): return int(sys.stdin.readline().strip())
def _ia(): return [int(x) for x in sys.stdin.readline().strip().split()]


n = _i()
xy = [_ia() for _ in range(n)]

tot = 0
for s in permutations([i for i in range(n)]):
    i = s[0]
    tmp = 0
    for j in s[1:]:
        dx = xy[i][0] - xy[j][0]
        dy = xy[i][1] - xy[j][1]
        tmp += sqrt(dx ** 2 + dy ** 2)
        i = j
    tot += tmp

print(tot / factorial(n))

Submission status: Accepted

Solution code:
import math
import itertools
import numpy as np
def l2_dist(a,b):
    return math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2)
def rate(n):
    if n == 1:
        return 2
    else:
        return n * rate(n - 1) 
def fact(n):
    if n == 1 or n == 0:
        return 1
    else:
        return n * fact(n - 1)
n = int(input())
point_list = []
for i in range(n):
    point_list.append(tuple(map(float,input().split(' '))))
dist_list = []
for i in itertools.combinations([i for i in range(n)], 2):
    dist_list.append(l2_dist(point_list[i[0]],point_list[i[1]]))
r = rate(n - 1) if n > 2 else 1
f = fact(n) if n > 2 else 1
dist_list = np.asarray(dist_list) * r
print(dist_list.sum() / f)

Submission status: Accepted

Solution code:
n = int(input())
s = 0
x = [0] * n
y = [0] * n
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):
        s += ((x[i]-x[j])**2 + (y[i]-y[j])**2) ** (1/2)

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

Submission status: Accepted

Solution code:
#AtCoder
from math import sqrt
N = int(input())
lst = [list(map(int, input().split())) for _ in range(N)]

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

Submission status: Accepted

Solution code:
import math

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

ans = 0
count = 1;
for i in range(1, N):
    count *= i

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


print(ans / count / N)

Submission status: Accepted

Solution code:
n=int(input())
import math
import itertools
#total=0
x=[]
y=[]
total=0
num=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
num_lis=[i for i in range(n)]
P=itertools.permutations(num_lis,n)
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/num)

Submission status: Accepted

Solution code:
n=int(input())
import math
import itertools
#total=0
x=[]
y=[]
total=0
num=math.factorial(n)
for i in range(n):
    X,Y=map(int,input().split())
    x.append(X)
    y.append(Y)
num_lis=[]
for i in range(n):
    num_lis.append(i)
P=itertools.permutations(num_lis,n)
for p in P:
    for i in range(n-1):
        tmp=math.sqrt((x[p[i+1]]-x[p[i]])**2+(y[p[i+1]]-y[p[i]])**2)
        total+=tmp
print(total/num)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
g = [[0] * n for i in range(n)]
for i,j in itertools.combinations(range(n),2):
  i,j = min(i,j),max(i,j)
  g[i][j] = ((l[i][0]-l[j][0])**2 + (l[i][1]-l[j][1])**2) ** 0.5
a = 0
c = 0
for i in itertools.permutations(range(n)):
  c += 1
  cur = i[0]
  for j in i[1:]:
    pre,cur = cur,j
    a += g[min(pre,cur)][max(pre,cur)]
print(a/c)

Submission status: Accepted

Solution code:
N = int(input())
P = [tuple(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        ans += ((P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2) ** 0.5

print(2 * ans / N)

Submission status: Accepted

Solution code:
import math
from itertools import permutations
 
N = int(input())
xy = [[int(i) for i in input().split()] for j in range(N)]
 
dist = [[0]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        dist[i][j] = math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
 
answer = 0.0
 
for i in permutations(range(N)):
    for j in range(1,N):
        answer += dist[i[j-1]][i[j]]
answer /= math.factorial(N)
 
print(answer)

Submission status: Accepted

Solution code:
# coding: utf-8
from itertools import permutations
from math import sqrt

def calc(x0, y0, x1, y1):
    return sqrt((x0 - x1) ** 2 + (y0 - y1) ** 2)

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

for l in ll:
    tmp = 0
    x0, y0 = X[l[0]], Y[l[0]]
    for j in range(1, N):
        x1, y1 = X[l[j]], Y[l[j]]
        tmp += calc(x0, y0, x1, y1)
        x0, y0 = x1, y1
    ls.append(tmp)
    
print(sum(ls) / len(ll))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Atcoder necoak answer
# https://atcoder.jp/contests/abc145/tasks/abc145_c

n_text = input()
n = int(n_text)

class Zahyo:
    def __init__(self, x, y):
        self.x = x
        self.y = y
    
    @staticmethod
    def parse(text):
        x_txt, y_txt = text.split()
        x = int(x_txt)
        y = int(y_txt)
        zahyo = Zahyo(x, y)
        return zahyo


def calc_kyori(zahyo1, zahyo2):
    kyori = (((zahyo1.x - zahyo2.x) ** 2) + ((zahyo1.y - zahyo2.y) ** 2)) ** 0.5
    return kyori


def calc_kyoris(my_zahyo_list):
    kyori = 0
    for i in range(len(my_zahyo_list)-1):
        kyori += calc_kyori(my_zahyo_list[i], my_zahyo_list[i+1])
    return kyori


zahyo_list = []
for i in range(n):
    zahyo_list.append(Zahyo.parse(input()))

kyori_list = []


def calc(my_kakutei_zahyo_list, my_un_kakutei_zahyo_list, my_kyori_list):
    # print(len(my_kakutei_zahyo_list), len(my_un_kakutei_zahyo_list))
    if len(my_un_kakutei_zahyo_list) == 0:
        kyori = calc_kyoris(my_kakutei_zahyo_list)
        my_kyori_list.append(kyori)
    for i in range(len(my_un_kakutei_zahyo_list)):
        calc(my_kakutei_zahyo_list + [my_un_kakutei_zahyo_list[i]], my_un_kakutei_zahyo_list[0:i] + my_un_kakutei_zahyo_list[i+1:], my_kyori_list)


calc([], zahyo_list, kyori_list)

heikin = sum(kyori_list) / len(kyori_list)
print(heikin)

Submission status: Accepted

Solution code:
N=int(input())
##c=list(map(int, input().split()))

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

k=0
for i in range(N):
    for j in range(N):
        if(i!=j):
            k=k+((a[i][0]-a[j][0])*(a[i][0]-a[j][0])+(a[i][1]-a[j][1])*(a[i][1]-a[j][1]))**0.5

print(k/N)

Submission status: Accepted

Solution code:
import math
import itertools
N = int(input())
town = []
kyori = []
for i in range(N):
  x,y = map(int, input().split())
  town.append([x,y])
  
for route in itertools.permutations(town, N):
  L = 0
  for i in range(N-1):
    L = L + math.sqrt((route[i+1][0]-route[i][0])**2 + (route[i+1][1]-route[i][1])**2)
  kyori.append(L)

print(sum(kyori)/math.factorial(N))

Submission status: Accepted

Solution code:
import math
import itertools

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


N = int(input())
S = []
for _ in range(N):
  S.append(list(map(int, input().split())))
l = [i for i in range(N)]
dic=[]
for v in itertools.permutations(l):
    dic.append(v)
#print(dic)
    
sum_l=0.0
for i in range(len(dic)):
  for j in range(N-1):
    sum_l += distance(S[dic[i][j]][0],S[dic[i][j]][1],S[dic[i][j+1]][0],S[dic[i][j+1]][1])
print(sum_l/len(dic))

Submission status: Accepted

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

def distance(xy_lst1,xy_lst2):
    xi = xy_lst1[0]
    yi = xy_lst1[1]
    xj = xy_lst2[0]
    yj = xy_lst2[1]

    d = ((xi-xj)**2 + (yi-yj)**2)**(0.5)
    return(d)

# make distance dictionary
d_dic = {}
d_sum = 0
for i in range(N):
    i_dic = {}
    for j in range(N):
        dij = distance(XY_lst[i], XY_lst[j])
        d_sum += dij
        i_dic[str(j)] = dij
    d_dic[str(i)] = i_dic
# print(d_dic)
        

# ansewer is culculated by 1/N * sum(dij): i,j included by N
print(d_sum / N)

Submission status: Accepted

Solution code:
import math

N = int(input())
pts = [[int(i) for i in input().split()] for _ in range(N)]
tot = 0
for i in range(N):
  tot += sum([math.sqrt((pts[i][0]-pts[j][0])**2+(pts[i][1]-pts[j][1])**2) for j in range(i+1, N)])
print(tot / math.factorial(N) * math.factorial(N-1) * 2)

Submission status: Accepted

Solution code:
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

import math
from functools import lru_cache

@lru_cache(maxsize=100000)
def calc_distance(a, b):
    tmp = (a[0]-b[0])**2 + (a[1]-b[1])**2
    return math.sqrt(tmp)


import itertools
sum = 0
for all in itertools.permutations(s, n):
    for i in range(n-1):
        # tupleにすることで、lru_cacheを使用可能にする．
        # listはハッシュ出来ないが、tupleはハッシュ可能．
        sum += calc_distance(tuple(all[i]), tuple(all[i+1])) 

kaizyo = math.factorial(n)
# print("sum:", sum)
# print("kaizyo:", kaizyo)

print(sum/kaizyo)

Submission status: Accepted

Solution code:
# C - Average Length

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

####

import math
import statistics
import itertools

table = [[0]*N for i in range(N)]
for i in range(N):
    ti = arr[i]
    for j in range(N):
        tj = arr[j]
        dist = math.sqrt((ti[0] - tj[0])**2 + (ti[1] - tj[1])**2)
        table[i][j] = dist

kumi_all = list(itertools.permutations(range(N)))
kumi_all_count = len(kumi_all)

total_dist = 0

for i in range(kumi_all_count):
    this_dist = 0
    this_kumi = kumi_all[i]

    for j in range(N-1):
        this_dist += table[this_kumi[j]][this_kumi[j+1]]

    total_dist += this_dist

avr_dist = total_dist / kumi_all_count

print(avr_dist)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n = int(input())
c = []
for i in range(n):
    x,y = map(int,input().split())
    c.append([x,y])
dist = []
for i in range(len(c)):
    for j in range(len(c)):
        dist.append(math.sqrt(pow(c[i][0]-c[j][0],2)+pow(c[i][1]-c[j][1],2)))
print(sum(dist)/n)

Submission status: Accepted

Solution code:
n = int(input())
a = [0]*n
b = [0]*n

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

c = 0

for i in range(n):
    for j in range(n):
        c += ((a[j]-a[i])**2 + (b[i]-b[j])**2)**0.5
print(c/n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
coord = list()
for i in range(n):
    x, y = map(int, input().split())
    coord.append([x, y])

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

dist = []
for i in range(n):
    temp = []
    for j in range(n):
        temp.append(calc_dist(coord[i], coord[j]))
    dist.append(temp)

summed = 0
for k in range(len(dist)):
    summed += sum(dist[k])

ans = summed / n

print(ans)

Submission status: Accepted

Solution code:
import itertools

N = int(input())
P = [list(map(int,input().split())) for i in range(N)]
number = 0
Sum = 0
for pair in itertools.permutations(P,N):
    for i in range(N-1):
        Sum = Sum + ((pair[i][0]-pair[i+1][0])**2+(pair[i][1]-pair[i+1][1])**2)**(1/2)
    number += 1
print(Sum/number)

Submission status: Accepted

Solution code:
import itertools
import math

def main():
    lists = []
    i=0
    N= int(input())
    while i < N:
        a = [int(j) for j in input().split()]
        lists.append(a)
        i+=1
    ans=0
    length=0
    for line in itertools.permutations(lists):
        a = []
        b = []
        for data in line:
            if len(b) ==0:
                b = data
                continue
            else:
                a = b
                b = data
                length = math.sqrt(((b[0]-a[0])**2)+((b[1]-a[1])**2))
                ans+=length
    print(ans/math.factorial(N))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

import numpy as np
import itertools as it

# Nの町

# 入力
# N
# x1 y1
# ...
# xn yn

N = int(input())
townpoints = np.empty((N, 2), dtype=np.int16)
distances = np.empty((N, N))

for i in range(N):
    line = input()
    townpoints[i] = list(map(int, line.split(' ')))

xx, xy = np.meshgrid(townpoints[:, 0], townpoints[:, 0])
yx, yy = np.meshgrid(townpoints[:, 1], townpoints[:, 1])

xdist = (xx - xy) ** 2
ydist = (yx - yy) ** 2

distances = (xdist+ydist)**0.5

# [(1,2,3), (2,1,3), ... ] all visit orders
orders = list(it.permutations(list(range(N))))

distance_list = np.empty((len(orders)))

for n, i in enumerate(orders):
    dist_tmp = 0
    for j in range(N-1):
        dist_tmp += distances[i[j], i[j+1]]
    distance_list[n] = dist_tmp

avg = distance_list.sum()/len(distance_list)

print(avg)

Submission status: Accepted

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

ans=0
for v in itertools.permutations(xy):
  x=[v[i][0] for i in range(n)]
  y=[v[i][1] for i in range(n)]

  for i in range(n-1):
    ans += ((x[i+1]-x[i])**2 + (y[i+1]-y[i])**2)**0.5

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

Submission status: Accepted

Solution code:
n=int(input())
s=[list(map(int,list(input().split()))) for i in range(n)]  # 二次元配列入力　二次元マップみたいな入力のとき

# print("n", n)
# print("s:", s)

import math

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

sum = 0
for i in s: 
    for j in s:
        dist = calc_distance(i, j)
        sum += dist

print(float(sum/n))

Submission status: Accepted

Solution code:
import math
def distance(x1,y1,x2,y2):
    x = pow(abs(x1-x2),2)
    y = pow(abs(y1-y2),2)
    return math.sqrt(x+y)

import itertools
# 順列生成
def permutation(list_):
    return list(itertools.permutations(list_))

def main():
    n = int(input())
    x,y = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        x[i],y[i] = map(int,input().split())
    
    can = permutation(list(range(n)))

    all_path = 0
    for ls in can:
        path = 0
        for i in range(1,len(ls)):
            path += distance(x[ls[i-1]],y[ls[i-1]],x[ls[i]],y[ls[i]])
        all_path += path
    
    print(all_path/len(can))

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
from math import sqrt, factorial
from itertools import permutations
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


class Solver(object):
    def __init__(self):
        pass

    def solve(self, N: int, cities: list):
        dist = float()
        for p in permutations(range(N)):
            for index, n in enumerate(p):
                if index == 0:
                    a = cities[n]
                    continue
                else:
                    b = a
                    a = cities[n]
                    dist += self.__distance(a, b)
        return dist/factorial(N)

    def __distance(self, a: list, b: list) -> float:
        return sqrt(abs(a[0]-b[0])*abs(a[0]-b[0]) + abs(a[1]-b[1])*abs(a[1]-b[1]))


def main():
    N = int(input())
    t_l = [[int(i) for i in input().split()] for _ in range(N)]

    solver = Solver()
    print(solver.solve(N, t_l))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

import math

n = int(input())

a = []

sum = 0

for i in range(n):
    a.append(np.array(list(map(int,input().split()))))

for i in range(n):
    for s in range(i,n):
        sum += np.linalg.norm(a[s] - a[i]) * math.factorial(n-1) * 2

print(sum/math.factorial(n))

Submission status: Accepted

Solution code:
n  = int(input())
a = []
for i in range(n):
    x,y = list(map(int,input().split()))
    a.append([x,y])
#print(a)
b = []
for i in range(n):
    for j in range(n-i-1):
        xi,yi = a[i]
        xj,yj = a[j+i+1]
 #       print(xi,yi,yi,yj)
        z = ((xi-xj)**2+(yi-yj)**2)**0.5
        b.append(z)
#print(b)
print(sum(b)/len(b)*(n-1))

Submission status: Accepted

Solution code:
import math
import heapq
import sys
from collections import Counter
import numpy as np

#N,K=map(int, input[0].split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
#x=list(map(int, input[1].split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
#s = [input() for i in range(3)]

N=int(input())
points = []
for i in range(N):
    p = str(input()).split(" ")
    points.append((int(p[0]), int(p[1])))

#print(points)

total_dis=0
for i in range(N):
    for j in range(i+1,N):
        total_dis+=math.sqrt((points[i][0]-points[j][0])**2+(points[i][1]-points[j][1])**2)
        #print(total_dis)
        
print(2*total_dis/N)

Submission status: Accepted

Solution code:
#!/usr/local/bin/python3
import math

def get_distance(p1, p2):
    return math.hypot(p1[0] - p2[0], p1[1] - p2[1])

N = int(input())
points = []
for i in range(N):
    p = str(input()).split(" ")
    points.append((int(p[0]), int(p[1])))

total_dist = 0
for i in range(N):
    for j in range(i,N):
        total_dist += get_distance(points[i], points[j])

print(2*total_dist/N)

Submission status: Accepted

Solution code:
import itertools

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

for i in itertools.combinations(l,2):
    ans += ((i[0][0]-i[1][0])**2 + (i[0][1]-i[1][1])**2)**(1/2)

print(ans*2/n)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

N = int(input())

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

p = permutations(points,N)

average = 0

for j in p:
    for k in range(0,len(j)-1):
        average += ((j[k+1][0] -j[k][0])**2 + (j[k+1][1] -j[k][1])**2)**0.5

print('{:.10f}'.format(average/factorial(N)))

Submission status: Accepted

Solution code:
import numpy as np


def main():
    N = int(input())
    xs = np.array([tuple(map(int, input().split()))
                   for _ in range(N)], np.float32)
    dmap = dist(xs)
    s = 0.
    for i, p in enumerate(permutations(np.arange(N))):
        d = sum(dmap[p[k - 1], p[k]] for k in range(1, N))
        s += d
    print(s / (i + 1))


def permutations(iterable, r=None):
    pool = tuple(iterable)
    n = len(pool)
    r = n if r is None else r
    if r > n:
        return
    indices = list(range(n))
    cycles = list(range(n, n-r, -1))
    yield tuple(pool[i] for i in indices[:r])
    while n:
        for i in reversed(range(r)):
            cycles[i] -= 1
            if cycles[i] == 0:
                indices[i:] = indices[i+1:] + indices[i:i+1]
                cycles[i] = n - i
            else:
                j = cycles[i]
                indices[i], indices[-j] = indices[-j], indices[i]
                yield tuple(pool[i] for i in indices[:r])
                break
        else:
            return


def dist(xs):
    x, y = xs.T
    z = np.sqrt(np.power(x[:, None] - x[None], 2)
                + np.power(y[:, None] - y[None], 2))
    return z


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
x, y = [], []
for i in range(n):
	a, b = map(int, input().split())
	x.append(a)
	y.append(b)
res = 0
for x1, y1 in zip(x, y):
	for x2, y2 in zip(x, y):
		res += ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
res /= n
print(res)

Submission status: Accepted

Solution code:
import itertools
import statistics
N = int(input())
place_list = [list(map(int, input().split())) for i in range(N)]
all_place_list = list(itertools.permutations(place_list))
dist_list =[]
for place_list_iter in all_place_list:
    dist_sum = 0
    for i, (x, y) in enumerate(place_list_iter):
        if i == 0:
            pre_x, pre_y = x, y
        else:
            dist = ((x-pre_x)**2+(y-pre_y)**2)**(1/2)
            dist_sum += dist
    dist_list.append(dist_sum)
print(statistics.mean(dist_list))

Submission status: Accepted

Solution code:
n = int(input())
df = [list(map(int, input().split())) for _ in range(n)]
m = 1
for i in range(1, n+1):
    m *= i
result = 0
for i in range(n):
    for j in range(n):
        if i != j:
            result += (abs(df[i][0]-df[j][0])**2 + abs(df[i][1] - df[j][1])**2)**0.5
print(result/n)

Submission status: Accepted

Solution code:
#!/usr/bin/pypy
N=int(raw_input())
xn=[]
for i in range(N):
    xn.append(map(int, raw_input().split()))

S = 0
for i in range(N):
    for j in range(N):
        S += pow( \
               pow(xn[i][0] - xn[j][0], 2) + \
               pow(xn[i][1] - xn[j][1], 2) , \
               0.5 \
             )

print str(S / N)

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq

N = int(input())

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

ans = 0
for a1 in A:
    for a2 in A:
        ans += math.sqrt((a1[0]-a2[0])**2 + (a1[1]-a2[1])**2)

ans /= N
print(ans)

Submission status: Accepted

Solution code:
List = []

def f(n):
    s = 0;
    for i in range(n):
        for j in range(n):
            if i != j:
                s += ((List[i][0] - List[j][0])**2 + (List[i][1] - List[j][1])**2)**0.5
    
    return s/n

if __name__ == '__main__':
    n = int(input())
    for i in range(n):
        x, y = map(int, input().split())
        List.append((x, y))
    print(f(n))

Submission status: Accepted

Solution code:
import itertools
import math

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

_list = list(itertools.permutations(xy))
a = []
for i in _list:
    b = 0
    for j in range(len(i)-1):
        a.append(math.sqrt(pow(i[j][0]-i[j+1][0], 2) + pow(i[j][1]-i[j+1][1], 2)))
print(sum(a)/len(_list))