Problem:


Score : 300 points

Problem Statement

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

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

Constraints

2 \leq N \leq 8

-1000 \leq x_i \leq 1000

-1000 \leq y_i \leq 1000

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

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

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
:
x_N y_N

Output

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

Sample Input 1

3
0 0
1 0
0 1

Sample Output 1

2.2761423749

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

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

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

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

Sample Input 2

2
-879 981
-866 890

Sample Output 2

91.9238815543

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

Sample Input 3

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

Sample Output 3

7641.9817824387



Sample input:
3
0 0
1 0
0 1


Sample output:
2.2761423749

Submission status: Accepted

Solution code:
from itertools import permutations

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

ans = []
for case in permutations([i for i in range(N)]):
    total = 0
    for i in range(len(case)-1):        
        total += ((dist[case[i]][0]-dist[case[i+1]][0])**2 + (dist[case[i]][1]-dist[case[i+1]][1])**2)**(1/2)
    ans.append(total)

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

Submission status: Accepted

Solution code:
from itertools import permutations, combinations

def main():
    n = int(input())
    x_l = [] ; y_l = []
    for _ in range(n):
        tmp_x, tmp_y = map(int, input().split())
        x_l.append(tmp_x) ; y_l.append(tmp_y)
    cnt = 0
    total_dist = 0
    for c in permutations(range(n)):
        # c の中から２辺の数繰り返す
        for i in range(n-1):
            dist = ((x_l[c[i]] - x_l[c[i+1]])**2 + (y_l[c[i]] - y_l[c[i+1]])**2)**(1/2)
            total_dist += dist
        cnt += 1

    print(total_dist/cnt)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import sqrt

n = int(input())

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

def dist(c1,c2):
	return(sqrt((c1[0]-c2[0])**2+(c1[1]-c2[1])**2))

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

avg = (2*distSum)/n
print(avg)

Submission status: Accepted

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

d = 0
for i in range(n):
    for j in range(i):
        x = a[i] - a[j]
        y = b[i] - b[j]
        d += sqrt(x**2 + y**2)
d *= 2
d /= n
print(d)

Submission status: Accepted

Solution code:
import itertools

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

jyunlist = [i for i in range(N)]
p_list = list(itertools.permutations(jyunlist))
a = 0
sum = 0
for keiro in p_list:
    for i in range(N-1):
        a = ((xylist[keiro[i+1]][0]-xylist[keiro[i]][0])**2+(xylist[keiro[i+1]][1]-xylist[keiro[i]][1])**2)**(1/2)
        sum += a
ans = sum/len(p_list)

print(ans)

Submission status: Accepted

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect

from itertools import permutations

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

cases = list(permutations(list(range(N)), N))

ans = 0
for case in cases:
    dist = 0
    for i in range(1, N):
        a, b = case[i-1], case[i]
        dist += ((data[a][0] - data[b][0])**2 + (data[a][1] - data[b][1])**2)**.5
    ans += dist

print(ans/len(cases))

Submission status: Accepted

Solution code:
import math

n = int(input())
xy_list = [list(map(int,input().split())) 
           for nesya in range(n)]
c = 0
for xy in xy_list:
  x = xy[0]
  y = xy[1]
  for ab in xy_list:
    a = ab[0]
    b = ab[1]
    c += math.sqrt((x-a)**2+(y-b)**2)
print(c/n)

Submission status: Accepted

Solution code:
N = int(input())
XY = [list(map(int, input().split())) for _ in range(N)]
dist = 0
for x1, y1 in XY:
    for x2, y2 in XY:
        dist += ((x1 - x2)**2 + (y1 - y2)**2)**(1/2)
print(dist/N)

Submission status: Accepted

Solution code:
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    N,=pin()
    p=[tupin() for _ in range(N)]
    def fact(k):
        if k==0:return 1
        return k*fact(k-1)
        
    ans=dict()
    for i in range(N-1):
        for j in range(i+1,N):
            temp=0
            for k in range(2):
                temp+=(p[i][k]-p[j][k])**2
            ans.setdefault(temp,0)
            ans[temp]+=1
    x=0
    for a in ans.items():
        x+=(a[0]**0.5)*a[1]
    #print(ans)
    print((x*2)/(N))
        
#%%submit!
resolve()

Submission status: Accepted

Solution code:
import itertools

n = int(input()) 
p_list = itertools.permutations([x for x in range(n)])

# for p in p_list:
#     print(p)

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


d_sum = 0
cnt = 0
for p in p_list:
    cnt+=1
    curr_d_sum = 0
    curr_pos = p[0]
    for i in p:
        x_d = a_list[curr_pos][0] - a_list[i][0]
        y_d = a_list[curr_pos][1] - a_list[i][1]
        d = (x_d**2 + y_d**2)**0.5
        curr_d_sum += d
        curr_pos = i
    d_sum += curr_d_sum
print(d_sum/cnt)

Submission status: Accepted

Solution code:
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

import itertools
import math

n = I()
p = [LI() for i in range(n)]

nums = range(n)
result = 0
count = 0
for lis in itertools.permutations(nums,n):
    x = 0
    for i in range(n-1):
        x += math.sqrt((p[lis[i+1]][1]-p[lis[i]][1])**2 + (p[lis[i+1]][0]-p[lis[i]][0])**2)
    
    result += x
    count += 1

print(result / count)

Submission status: Accepted

Solution code:
import itertools, math

n = int(input())
xy = []
kai = 1
for i in range(n):
    xy.append(list(map(int, input().split())))
    kai *= (i + 1)
    
cost = 0
for lst in itertools.permutations(range(n), n):
    x = xy[lst[0]][0]
    y = xy[lst[0]][1]
    for num in lst:
        dx = xy[num][0] - x
        dy = xy[num][1] - y
        cost += math.sqrt(dx ** 2 + dy ** 2)
        x = xy[num][0]
        y = xy[num][1]
print(cost / kai)

Submission status: Accepted

Solution code:
# coding: utf-8
import re
import math
from collections import defaultdict
from collections import deque
import itertools
from copy import deepcopy
import random
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
#@lru_cache(maxsize=None)
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_pow(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def get_primes(n,type="int"):
    if n==0:
        if type=="int":return []
        else:return [False]
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=""):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
    return ret
def seifu(x):
    return x//abs(x)
###################################################
def main():
    n=int(input())
    facs=get_facs(n+5)
    ans=0
    x=[0]*n
    y=[0]*n
    for a in range(n):x[a],y[a]=map(int,input().split())
    for a in range(n):
        for b in range(n):
            ans+=facs[n-1]*math.sqrt((x[a]-x[b])**2+(y[a]-y[b])**2)
    ans/=facs[n]
    print(ans)
main()

Submission status: Accepted

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


x = [i for i in range(n)]
candi = itertools.permutations(x)

dist = 0
count = 0
for i in candi: #経路の候補を作成
  for j in range(0,n-1):
    now = a[i[j]] # いまのx座標now[0],y座標[1]
    next = a[i[j+1]] # 次の座標
    dist += math.sqrt((next[0] - now[0])**2 + (next[1] - now[1])**2)
  count += 1

print(dist/count)

Submission status: Accepted

Solution code:
import itertools
n = int(input())
xy = [[]]*n
for i in range(n):
  xy[i] = list(map(int,input().split()))
routes = list(itertools.permutations(list(range(n))))
routenum = len(routes)
routeavg = 0
for i in routes:
  curroute = 0
  for j in range(1,n):
    curroute += ((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
  routeavg += curroute/routenum
print(routeavg)

Submission status: Accepted

Solution code:
n = int(input())
p = [list(map(int, input().split())) for _ in range(n)]
import numpy as np
import math
import itertools
t = math.factorial(n)/(math.factorial(2)*math.factorial(n-2))
# print(t)
dist = np.zeros(int(t))
count =0
for i in range(n-1):
    # print(i)
    for j in range(i+1,n):
        # print(j,'j')
        dist[count] = math.sqrt(pow(p[i][0]-p[j][0],2)+pow(p[i][1]-p[j][1],2))
        count += 1

# print(dist)
print(2*sum(dist)/n)

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())

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

list_per = list(itertools.permutations(list(range(N))))
num = len(list_per)

llength = list()
for i in range(num):
    length = 0
    for j in range(N-1):
        length += math.sqrt((lloc[list_per[i][j]][0] - lloc[list_per[i][j+1]][0])**2 + (lloc[list_per[i][j]][1] - lloc[list_per[i][j+1]][1])**2)
    llength.append(length)

print(sum(llength)/len(llength))

Submission status: Accepted

Solution code:
import itertools
N = int(input())
place = [list(map(int,input().split())) for _ in range(N)]
d_sum = 0
perm_len = 0
for p in itertools.permutations(list(range(N))):
    perm_len += 1
    for i in range(1,N):
        d_sum += ((place[p[i-1]][0]-place[p[i]][0])**2 + (place[p[i-1]][1]-place[p[i]][1])**2)**(1/2)
print(d_sum/perm_len)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial

N = int(input())

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

i = 0
length = []
for comb in permutations(range(1, N+1), N):
    tmp = 0
    for i in range(len(comb)-1):
        tmp += ((x[comb[i+1]-1] - x[comb[i]-1])**2 + (y[comb[i+1]-1] - y[comb[i]-1])**2)**(1/2)
    length.append(tmp)
print(sum(length)/factorial(N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import itertools
import math


def distance():
    N = int(input())
    x_y = [tuple(map(int, input().split())) for _ in range(N)]
    combis = list(itertools.permutations(x_y, N))

    def euclid(p1, p2):
        return math.sqrt((pow((p1[0] - p2[0]), 2) + pow((p1[1] - p2[1]), 2)))
    result = 0
    for combi in combis:
        for i in range(len(combi)-1):
            result += euclid(combi[i], combi[i+1])
    print(float(result / len(combis)))


if __name__ == "__main__":
    distance()

Submission status: Accepted

Solution code:
import math
import itertools


N = int(input())

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

permutation_list = itertools.permutations([x for x in range(N)])

calc = [[0] * 10 for i in range(10)]
for i in range(N):
    for j in range(N):
        calc[i][j] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
                               (array[i][1] - array[j][1]) ** 2)
        calc[j][i] = calc[i][j]

result = 0
count = 0
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)

Submission status: Accepted

Solution code:
import math
import itertools


N = int(input())

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

result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])

calc = [[0] * 10 for i in range(10)]
for i in range(N):
    for j in range(N):
        calc[i][j] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
                               (array[i][1] - array[j][1]) ** 2)
        calc[j][i] = math.sqrt((array[i][0] - array[j][0]) ** 2 +
                               (array[i][1] - array[j][1]) ** 2)

for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += calc[data[i - 1]][data[i]]
print(result / count)

Submission status: Accepted

Solution code:
from itertools import permutations
from math import factorial
n = int(input())
towns = [list(map(int, input().split())) for _ in range(n)]
path_length = 0
for p in permutations(towns):
    for (x1, y1), (x2, y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5 
ans = path_length / factorial(n)
print(ans)

Submission status: Accepted

Solution code:
import math
import itertools


N = int(input())

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

result = 0
count = 0
permutation_list = itertools.permutations([x for x in range(N)])
for data in permutation_list:
    count += 1
    for i in range(1, len(data)):
        result += math.sqrt((array[data[i]][0] - array[data[i - 1]][0]) ** 2 +
                            (array[data[i]][1] - array[data[i - 1]][1]) ** 2)
print(result / count)

Submission status: Accepted

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

for i in range(1,n+1):
    n2 *=i
ans = 0
for j in pattern:
    for k in range(n-1):
        ans += ((xy[j[k+1]][0] - xy[j[k]][0])**2 + (xy[j[k+1]][1] - xy[j[k]][1])**2)**0.5

print(ans/n2)

Submission status: Accepted

Solution code:
from math import sqrt

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

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

Submission status: Accepted

Solution code:
import itertools
import math
n=int(input())
xy=[list(map(int,input().split())) for i in range(n)]
ans=0
for i in itertools.permutations(xy,n):
  sum=0
  for t in range(n-1):
    sum+=((i[t][0]-i[t+1][0])**2+(i[t][1]-i[t+1][1])**2)**(1/2)
  ans+=sum
print(ans/math.factorial(n))

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N=int(input())
    xy=[[int(_) for _ in input().split()] for _ in range(N)]
    distance = 0
    for i in range(N-1):
        for j in range(i, N):
            distance += ( (xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2 ) ** 0.5
    print(distance / (N/2))

main()

Submission status: Accepted

Solution code:

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

Submission status: Accepted

Solution code:
import numpy as np
import itertools 
def distance(a,b):
    x1,y1 = a
    x2,y2 = b
    return np.sqrt((x1-x2)**2 + (y1- y2)**2)
n = int(input())
xy = []
for _ in range(n):
    x,y = map(int,input().split())
    xy.append([x,y])
n_permutations = itertools.permutations(range(n))
dist_list=[]
for one_case in n_permutations:
    dist = 0
    for i in range(n-1):
        a = xy[one_case[i]]
        b = xy[one_case[i+1]]
        dist += distance(a,b)
    dist_list.append(dist)
print(sum(dist_list)/len(dist_list))

Submission status: Accepted

Solution code:
n = int(input())
a = []
for i in range(n):
  x,y=map(int,input().split())
  a.append((x,y))
s = 0
import itertools
import math
import fractions
for l in itertools.permutations(range(n)):

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

Submission status: Accepted

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

for i in range(n):
  x, y = map(int, input().split());
  X.append(x);
  Y.append(y);
    
list_ = list(itertools.permutations(range(n)))
ans = 0
ans_list = []

for i in list_:
  for j in range(n - 1):
    ans += ((X[i[j + 1]] - X[i[j]]) ** 2 + (Y[i[j + 1]] - Y[i[j]]) ** 2) ** (1 / 2)
  
  ans_list.append(ans)
  ans = 0 
  
print(sum(ans_list) / len(ans_list))

Submission status: Accepted

Solution code:
#import numpy as np
import sys
import math
from collections import defaultdict
import itertools
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

ans = 0
fa = 0

for x in list(itertools.permutations( [i for i in range(1,N+1)] , N)):
    for i in range(N-1):
        xx = coordinate[x[i]-1][0] - coordinate[x[i+1]-1][0]
        y = coordinate[x[i]-1][1] - coordinate[x[i+1]-1][1]
        ans += math.sqrt(xx**2 + y ** 2)
    fa += 1
print(ans/fa)

Submission status: Accepted

Solution code:
#import numpy as np
import sys
import math
from collections import defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.readline
readlines = sys.stdin.buffer.readlines

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

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

ans = 0.0
for i in range(N):
    for j in range(N):
        ans = ans + math.sqrt( (coordinate[i][0] - coordinate[j][0]) ** 2 + (coordinate[i][1] - coordinate[j][1]) ** 2)
print(ans * foactorial / (foactorial * N) )

Submission status: Accepted

Solution code:
import itertools
import math

n = int(input())
x = [list(map(int, input().split())) for i in range(n)]
lis = [x for x in range(n)]
p_lis = itertools.permutations(lis)
s = 0

for i in p_lis:
    for j in range(n-1):
        r = ((x[i[j+1]][0] - x[i[j]][0])**2 + (x[i[j+1]][1] - x[i[j]][1])**2) **0.5
        s += r
ans = s/math.factorial(n)
print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())
x = []
y = []
for _ in range(N):
  a, b = map(int, input().split())
  x.append(a)
  y.append(b)
d = []
# 道の長さをリストdに加えていく
# dは8C2=28個の要素を持つ
for i in range(N - 1):
  for j in range(i + 1, N):
    d.append(math.sqrt((x[j] - x[i]) ** 2 + (y[j] - y[i]) ** 2))
#N=8のとき
#dは8*7/2/1個
#一つの道につき7!*2回使う
#道は全部で8!*7通る
#ans = (sum(d) * math.factorial(N - 1) * 2) / math.factorial(N)
ans = sum(d) * 2 / N
print(ans)

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

N = INT()
xy = [LIST() for _ in range(N)]

distance = 0
cnt = 0

for p in permutations(xy, N):
	cnt += 1
	for i in range(N-1):
		distance += dist(p[i], p[i+1])

print(distance/cnt)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# C - Average Length
from itertools import permutations


def main():
    temp = 0
    n = int(input())
    plot_list = [list(map(int,input().split())) for _ in range(n)]
    case = list(permutations(range(n)))

    for c in case:
        for i in range(n-1):
            temp += ((plot_list[c[i]][0] - plot_list[c[i+1]][0])**2 + (plot_list[c[i]][1] - plot_list[c[i+1]][1])**2)**0.5

    print(temp/len(case))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
import itertools
def distance(xi,yi,xj,yj):
    return(math.sqrt((xi-xj)**2+(yi-yj)**2))
n = int(input())
xy = []
for i in range(n):
    li = list(map(int,input().split()))
    xy.append(li)
dis_li = []
count = 0
for it in itertools.permutations(xy):
    dis = 0
    for i in range(len(it)-1):
        dis += distance(it[i][0],it[i][1],it[i+1][0],it[i+1][1])
    dis_li.append(dis)
    count += 1
print(sum(dis_li)/count)

Submission status: Accepted

Solution code:
from itertools import permutations

n = int(input())

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

s = 0
count = 0

for i in permutations(range(n), n):
    count += 1
    for a, b in zip(i, i[1:]):
        s += ((lis[a][0] - lis[b][0])**2 + (lis[a][1] - lis[b][1])**2) ** 0.5

print(s/count)

Submission status: Accepted

Solution code:
import itertools

n=int(input())
li=[list(map(int,input().split())) for _ in range(n)]
ans,div=[],0

for i in itertools.permutations(range(n),n):
  div+=1
  dis=0
  for a,b in zip(i,i[1:]):
    dis += ((li[b][0]-li[a][0])**2 + (li[b][1]-li[a][1])**2)**0.5
  ans.append(dis)

print(sum(ans)/div)

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

from math import sqrt
from itertools import permutations

length = []
r = list(permutations(range(n)))

for i in r:
    for j in range(n-1):
        x1 = x[i[j]][0]
        y1 = x[i[j]][1]
        x2 = x[i[j+1]][0]
        y2 = x[i[j+1]][1]
        length.append(sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)))

print(sum(length)/len(r))

Submission status: Accepted

Solution code:
import itertools
import math

N = int(input())
pl = itertools.permutations([i for i in range(N)])
xy = [list(map(int, input().split())) for _ in range(N)]
s = 0
for l in pl:
    for i in range(N - 1):
        xi, yi = xy[l[i]]
        xj, yj = xy[l[i + 1]]
        s += ((xi - xj)**2 + (yi - yj)**2)**0.5
print(s / math.factorial(N))

Submission status: Accepted

Solution code:
n = int(input())
clist = []
for i in range(n):
  cx, cy = list(map(int, input().split()))
  c = [cx, cy]
  clist.append(c)
dlist = []
for j in range(n):
  sc = clist[j]
  for k in range(j + 1, n):
    dc = clist[k]
    d = ((sc[0] - dc[0]) ** 2 + (sc[1] - dc[1]) ** 2) ** 0.5
    dlist.append(d)
print(sum(dlist) / n * 2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

xy_list = list()

for _ in range(N):
    xy_list.append( tuple(map(int, input().split() )) )

# for x, y in xy_list:
#     print(x,y)

from math import sqrt

def calc_dist(p1, p2):
    p1_x, p1_y = p1
    p2_x, p2_y = p2

    return sqrt((p2_x-p1_x)**2 + (p2_y-p1_y)**2)

from itertools import permutations
A_perm = permutations(xy_list, N)

sum_all = 0
cnt = 0
for a in A_perm:
    sum_dist = 0
    #for x,y in a:
    for i in range(len(a)-1):
        sum_dist = sum_dist + calc_dist(a[i], a[i+1])
    # print(sum_dist)

    sum_all = sum_all + sum_dist
    cnt = cnt + 1

print(sum_all / cnt)

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
X = []
Y = []
s = 0
for i in range(n):
    x,y = input().split()
    X.append(int(x))
    Y.append(int(y))

for i in range(n):
    for j in range(n):
        a = X[i] - X[j]
        b = Y[i] - Y[j]
        s += sqrt(a*a + b*b)
print(s/n)

Submission status: Accepted

Solution code:
import math
import itertools

# sqrt = math.sqrt((4 - 1) ** 2 + (4 - 1) ** 2)
# print(sqrt)

N = int(input())

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

paths = []
for one_case in itertools.permutations(P):
    sum_path = 0
    for i in range(len(P)):
        if i == len(P) - 1:
            break
        sum_path = sum_path + math.sqrt(
            (one_case[i][0] - one_case[i + 1][0]) ** 2 + (one_case[i][1] - one_case[i + 1][1]) ** 2)
    paths.append(sum_path)

print(sum(paths) / len(paths))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')



n = I()
XY = LIR(n)
D = [[0]*n for _ in range(n)]
for i, j in combinations(range(n), 2):
    x1 = XY[i][0]
    y1 = XY[i][1]
    x2 = XY[j][0]
    y2 = XY[j][1]
    D[i][j] = sqrt((x1-x2)**2+(y1-y2)**2)

tmp = 0
for Z in permutations(range(n), n):
    a = 0
    for i in range(n-1):
        b = min(Z[i], Z[i+1])
        c = max(Z[i], Z[i+1])
        a += D[b][c]
    tmp += a
print(tmp/factorial(n))

Submission status: Accepted

Solution code:
from math import sqrt
n = int(input())
x,y,s = [],[],0
for _ 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):
        a = x[i]-x[j]
        b = y[i]-y[j]
        s += sqrt(a*a+b*b)
print(s/n)

Submission status: Accepted

Solution code:
n = int(input())
ls = [list(map(int,input().split())) for i in range(n)]
a = 0
for j in range(n):
    for k in range(n):
        if j < k:
            a += ((ls[k][0]-ls[j][0])**2+(ls[k][1]-ls[j][1])**2)**(1/2)
b = a/(n*(n-1)/2)
print(b*(n-1))