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: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

city = np.array(city)

mid = city.mean(axis=0)

def calc_distance(a, b):
    d = a - b
    d = np.sqrt(np.sum(d * d))
    return d

all_distance = 0

for c in city:
    all_distance += calc_distance(mid, c)

print(all_distance)

Submission status: Wrong Answer

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

L = 0
for i in range(len(xy)-1):
  a = xy[i][0]-xy[i+1][0]
  b = xy[i][1]-xy[i+1][1]
  l = np.sqrt( a**2 +b**2)
  L += l
print(L)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

def D(a,b):
    a=a-1
    b=b-1
    return ((x[a]-x[b])**2+(y[a]-y[b])**2)**(0.5)
dp=[[0]*(n+1) for _ in range(2**n)]
for i in range(1,2**n):
    for j in range(1,n+1):
        for k in range(1,n+1):
            if (i>>(j-1))&1 and not (i>>(k-1)&1):
                dp[i+2**(k-1)][k]+=dp[i][j]+D(j,k)
print(sum(dp[2**n-1])/p)

Submission status: Wrong Answer

Solution code:
import itertools
import math

def dist(x1, y1, x2, y2):
  return math.sqrt((x1-x2)**2 + (y1-y2)**2)

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

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

Submission status: Wrong Answer

Solution code:
from math import sqrt as s
from math import factorial as f

def func(x1, x2, y1, y2): return s((x2-x1) ** 2 + (y2-y1) ** 2)

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

total = 0

for i in range(N-1):
  for j in range(i+1, N):
    total += func(xy[i][0], xy[j][0], xy[i][1], xy[j][1])

print(total / f(N))

Submission status: Wrong Answer

Solution code:
import itertools
import math

n = int(input())
x = []
num = []
for i in range(n):
  x.append([int(t) for t in input().split()])
  num.append(i)
ans = 0
for i in itertools.permutations(num):
  s = 0
  for j in range(n-1):
    s += math.sqrt((x[j][0] - x[j+1][0])**2 + (x[j][1] - x[j+1][1])**2)
  ans += s
ans /= n
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

def recursive(pos):
    if len(pos) == 1:
        return 0
    dist = 0
    for p in range(len(pos) - 1):
        dist += distance(pos[0], pos[p + 1])
    dist += recursive(pos[1:])
    return dist

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

print(recursive(pos) * (N - 1) * 2 / (math.factorial(N)))

Submission status: Wrong Answer

Solution code:
import math

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

def recursive(pos):
    if len(pos) == 1:
        return 0
    dist = 0
    for p in range(len(pos) - 1):
        dist += distance(pos[0], pos[p + 1]) + recursive(pos[1:])
    return dist

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

print(recursive(pos) / (math.factorial(N) / N))

Submission status: Wrong Answer

Solution code:
import math

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

def recursive(pos):
    if len(pos) == 1:
        return 0
    dist = 0
    for p in range(len(pos) - 1):
        dist += distance(pos[0], pos[p + 1]) + recursive(pos[1:])
    return dist

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

print(recursive(pos) / (math.factorial(N) / 2))

Submission status: Wrong Answer

Solution code:
import math

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

def recursive(pos):
    if len(pos) == 1:
        return 0
    dist = 0
    for p in range(len(pos) - 1):
        dist += distance(pos[0], pos[p + 1])
    return dist

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

print(recursive(pos))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 02:04:12 2020

@author: liang
"""
import math

N = int(input())
d = list()
for i in range(N):
    x, y = map(int,input().split())
    d.append((x,y))
#print(d)
lis = list(range(N))
num = list()
perm_list = list()

def make_perm():
    if len(num) == N:
        perm_list.append(num.copy())
    for n in lis:
        a = lis.pop(0)
        num.append(a)
        make_perm()
        num.pop()
        lis.append(a)
        
make_perm()
print(len(perm_list))
res = 0
for nums in perm_list:
    tmp = 0
    for i in range(N-1):
        tmp += math.sqrt((d[nums[i]][0]-d[nums[i+1]][0])**2 + (d[nums[i]][1] - d[nums[i+1]][1])**2)
    res += tmp
print(res/len(perm_list))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Wed Sep  9 02:04:12 2020

@author: liang
"""
import math

N = int(input())
d = list()
for i in range(N):
    x, y = map(int,input().split())
    d.append((x,y))
#print(d)
lis = list(range(N))
num = list()
perm_list = list()

def make_perm():
    if len(num) == N:
        perm_list.append(num.copy())
    for n in lis:
        a = lis.pop(0)
        num.append(a)
        make_perm()
        num.pop()
        lis.append(a)
        
make_perm()
res = 0
for nums in perm_list:
    tmp = 0
    for i in range(N-1):
        tmp += math.sqrt((d[i][0]-d[i+1][0])**2 + (d[i][1] - d[i+1][1])**2)
    res += tmp
print(res/len(perm_list))

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

s = 0
permutations = list(itertools.permutations(range(N)))
for l in permutations:
  tmp = 0
  for i in range(len(l)-1):
    print(i)
    tmp += math.sqrt((xy[i+1][0] - xy[i][0])**2 + (xy[i+1][1] - xy[i][1])**2)
  s += tmp
            
print(s / len(permutations))

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

s = 0
permutations = list(itertools.permutations(range(N)))
for l in permutations:
  tmp = 0
  for i in range(len(l)-1):
    tmp += math.sqrt((xy[i+1][0] - xy[i][0])**2 + (xy[i+1][1] - xy[i][1])**2)
  s += tmp
            
print(s / len(permutations))

Submission status: Wrong Answer

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

xi = []
yi = []

for i in range(N):
    x, y = map(int, input().split())
    xi.append(x)
    yi.append(x)
    
result = 0
for i in range(N):
    for j in range(N):
            result += math.sqrt((xi[j] - xi[i])*(xi[j] - xi[i]) + (yi[j] - yi[i])*(yi[j] - yi[i]))
            
print(result/N)

Submission status: Wrong Answer

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


xi = []
yi = []

for i in range(N):
    x, y = map(int, input().split())
    xi.append(x)
    yi.append(x)
    
result = 0
for i in range(N):
    for j in range(N):
        if i != j : 
            result += math.sqrt((xi[j] - xi[i])**2 + (yi[j] - yi[i])**2)
            
print(result/N)

Submission status: Wrong Answer

Solution code:
import itertools

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


cnt=0
num=0
for v in itertools.permutations(xy):
  num+=1
  for i in range(n-1):
    a=(v[i][0]-v[i+1][0])**2+(v[i][1]-v[i+1][1])**2
    b=a**0.5
    print(b)
    cnt+=b

print(cnt/num)

Submission status: Wrong Answer

Solution code:
import math

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

a=0

for i in range(n):
    if i==0:
        a+=((c[-1][0]-c[0][0])**2+(c[-1][1]-c[0][1])**2)**(0.5)
    else:
        a+=((c[i][0]-c[i-1][0])**2+(c[i][1]-c[i-1][1])**2)**(0.5)

ans=(a/n)*(n-1)
print(ans)

Submission status: Wrong Answer

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

a=0

for i in range(n):
    if i==0:
        a+=((c[-1][0]-c[0][0])**2+(c[-1][1]-c[0][1])**2)**(0.5)
    else:
        a+=((c[i][0]-c[i-1][0])**2+(c[i][1]-c[i-1][1])**2)**(0.5)

b=((n-1)*(math.factorial(n)))//n #1区間の出現回数

print((a*b)/(math.factorial(n)))

Submission status: Wrong Answer

Solution code:
import itertools
import math

n = int(input())
points = [list(map(int, input().split())) for _ in range(n)]
numbers = list(range(1, n + 1))
diff = 0
count = 0
for pattern in itertools.permutations(numbers):
    count += 1
    for j in range(n - 1):
        points_index = pattern[j] - 1
        next_index = pattern[j + 1] - 1
        diff += math.sqrt((points[points_index][0] - points[points_index][1]) ** 2 + (points[next_index][0] - points[next_index][1]) ** 2)

print(diff / count)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
n = int(input())
seq = [i for i in range(n)]
steps = list(itertools.permutations(seq))
xy = [list(map(int,input().split())) for _ in range(n)]
sumlen = 0
for j in range(len(steps)):
    leng = 0
    step = steps[j]
    for k in range(n-1):
        x_1 = int(xy[step[k]][0])
        x_2 = int(xy[step[k+1]][0])
        y_1 = int(xy[step[k]][1])
        y_2 = int(xy[step[k+1]][1])
        leng += ((x_1 - x_2)**2  + (y_1 - y_2)**2)**0.5
    sumlen += leng
    print(sumlen)
print((sumlen/len(steps)))

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i,j in combinations(town,2):
    ans += ((i[0]-j[0])**2 + (i[1]-j[1])**2)**0.5
print ((N-1)*ans/N)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i,j in combinations(town,2):
    ans += ((i[0]-j[0])**2 + (i[1]-j[1]**2))**0.5
print ((N-1)*ans/N)

Submission status: Wrong Answer

Solution code:
from itertools import combinations
N = int(input())
town = []
for n in range(N):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i,j in combinations(town,2):
    ans += ((i[0]-j[0])**2 + (i[1]-j[1]**2))**0.5
print (2*ans/N)

Submission status: Wrong Answer

Solution code:
#C - Average Length
import math
import itertools
N = int(input())
town = []
for i in range(N):
    x,y = map(int,input().split())
    town.append((x,y))

def dist(A,B):
    return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2)
route = list(itertools.permutations(town))
print(route)
tot = 0
for i in route:
    for j in range(len(i)-1):
        tot += dist(i[j],i[j+1])
ave = tot/len(route)
print(ave)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]

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

import itertools

seq=[i for i in range(n)]
p=list(itertools.permutations(seq))
import math

ans=0
for pp in p:
  for i in range(n-1):
    xy=math.sqrt((l[pp[i]][0]-l[pp[i+1]][0])**2 + (l[pp[i]][1]-l[pp[i+1]][1])**2)
    ans+=xy
print(len(p))
print(ans/len(p))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]

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

import itertools

seq=[i for i in range(n)]
p=list(itertools.permutations(seq))
import math

ans=0
for pp in p:
  for i in range(n-1):
    xy=math.sqrt((l[pp[i]][0]+l[pp[i+1]][0])**2 + (l[pp[i]][1]+l[pp[i+1]][1])**2)
    ans+=xy

print(ans/len(p))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        print(i, k)
        ans.append((((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2)**0.5)
print(sum(ans)*2/N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        print(i, k)
        ans.append(np.sqrt(((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2))
print(sum(ans)*2/N)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [tuple(map(int, input().split())) for _ in range(N)]
ans = []
import numpy as np
for i in range(len(A)-1):
    for k in range(i+1,len(A)):
        print(i, k)
        ans.append(np.sqrt(((A[i][0]-A[k][0])**2)+(A[i][1]-A[k][1])**2))
print(sum(ans)*2/len(ans))

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
import math
from collections import defaultdict,deque
from itertools import permutations
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

t=ii()
lol=[]
for i in range(t):
    a,b=ml()
    lol.append([a,b])
yo=0    
cnt=1
for i in list(permutations(lol)):
    for j in range(1,len(i)):
        x=i[j][0]-i[j-1][0]
        y=i[j][1]-i[j-1][1]
        yo+=math.sqrt(x*x+y*y)
    cnt+=1
print(yo/cnt)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
from math import sqrt, pow, factorial

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

sum = 0

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))



for i in permutations(range(n)):
    distance = 0
    for j in range(1, n):
        distance = calc(xy[i[j]], xy[i[j-1]])
    sum += distance
print(sum / factorial(n))

Submission status: Wrong Answer

Solution code:
from itertools import permutations
from math import sqrt, pow

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

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2))
ans = 0
for i in permutations(range(n)):
    tmp = 0
    for j in range(1, n):
        tmp = calc(l[i[j]], l[i[j-1]])
    ans += tmp
print(ans/n)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
from math import sqrt, pow, factorial

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

def calc(a, b):
    [x1, y1] = a
    [x2, y2] = b
    return sqrt(pow(x1 - x2, 2) + pow(y1 -y2, 2))
ans = 0
for order in permutations(range(N)):
    tmp = 0
    for i in range(1, N):
        tmp += calc(l[order[i]], l[order[i-1]])
    ans += tmp
print(ans/factorial(N))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

def solve():
    N = int(input())
    c = []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        c.append([x_tmp, y_tmp])
    l = [i for i in range(N)]

    sum_dist = 0
    ave_dist = 0
    for p in itertools.permutations(l):
        print(p)
        for i in range(len(p)-1):
            sum_dist += dist(c[p[i]], c[p[i+1]])
    ave_dist = sum_dist/len(list(itertools.permutations(l)))
    print(ave_dist)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import itertools
import math

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

def solve():
    N = int(input())
    c = []
    for _ in range(N):
        x_tmp, y_tmp = list(map(int, input().split()))
        c.append([x_tmp, y_tmp])
    l = [i for i in range(N)]

    sum_dist = 0
    ave_dist = 0
    for p in itertools.permutations(l):
        print(p)
        for i in range(len(p)-1):
            sum_dist += dist(c[i], c[i+1])
    ave_dist = sum_dist/len(list(itertools.permutations(l)))
    print(ave_dist)

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np


n = int(input())

xy=np.empty(2)
for _ in range(n):
    xy=np.vstack( [xy, [int(i) for i in input().split()]] )
xy=np.delete(xy,0,0)


ave=0.0
ls = list(itertools.permutations(range(n)))
for route in ls:
    dist=0.0
    for i in range(n-1):
        dist += np.linalg.norm(xy[route[i]]-xy[route[i+1]])
    ave += dist/(n-1)
print(ave/n)

Submission status: Wrong Answer

Solution code:
import itertools
import numpy as np


n = int(input())

xy=np.empty(2)
for _ in range(n):
    xy=np.vstack( [xy, [int(i) for i in input().split()]] )
xy=np.delete(xy,0,0)


ave=0.0
ls = list(itertools.permutations(range(n)))
for route in ls:
    dist=0.0
    for i in range(n-1):
        dist = (dist*(i) + np.linalg.norm(xy[route[i]]-xy[route[i+1]]))/(i+1)
    ave += dist
print(ave/n)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

D = []
for i in range(n):
    for j in range(i+1,n):
        D.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)

print(D)
ans = sum(D)*2/n
print(ans)

Submission status: Wrong Answer

Solution code:
import math
n=int(input())
s=[]
for i in range(n):
  m=[int(x) for x in input().split()]
  s.append(m)
d=0
for i in range(n-1):
  for j in range(i+1,n):
    d+=math.sqrt((s[i][0]-s[j][0])**2+(s[i][1]-s[j][1])**2)
ans=d*(n-1)/n
print(ans)

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

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

N = I()
#H,N = LI()
_XY = [LI() for _ in range(N)]
# X,Y = zip(*XY)
XY = np.array(_XY)
#C = np.zeros(N + 1)
# print(XY)

# print(np.linalg.norm(XY[1]-XY[0]))

def calcdis(p1,p2):
    return np.linalg.norm(p2-p1)

ans = []
for i in range(N):
    tmp = 0
    for j in range(N):
        if not i==j:
            print(i,j)
            tmp += calcdis(XY[i],XY[j])
    ans.append(tmp)
print(np.average(ans))

# if ans:
#     print('Yes')
# else:
#     print('No')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import itertools

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

N = int(input())
Cord = []
ls = list(itertools.permutations(range(N)))
for _ in range(N):
    Cord.append(tuple(map(int,input().split())))
ans = 0
print(ls)
for l in ls:
    for i in range(N-1):
        ans+=distance(Cord[l[i]],Cord[l[i+1]])
print(ans/len(ls))

Submission status: Wrong Answer

Solution code:
import numpy as np
n= int(input())
m = np.zeros((n,2))
sum1 = 0
for i in range(n):
    m[i] = list(map(int,input().split()))
for j in range(n-1):
    for k in range(j+1,n):
        sum1 = sum1 + ((m[j][0] - m[k][0])**2 + (m[j][1]-m[k][1])**2)**(1/2)


ans = 0
mul =1
for l in range(n):
    mul *= n-l
ans = (sum1*(2**(n-1)))/mul
print(ans)

Submission status: Wrong Answer

Solution code:
import math

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

num_nodes = n * (n - 1)
num_node_sel_total = math.factorial(n) * (n - 1)
num_node_sel = num_node_sel_total / num_nodes

print(num_node_sel)

ans = 0
for src in range(n):
    for dst in range(n):
        if src != dst:
            (src_x, src_y) = pts[src]
            (dst_x, dst_y) = pts[dst]
            d = math.sqrt((dst_x - src_x) ** 2 + (dst_y - src_y) ** 2)
            ans += d * num_node_sel
print(ans/math.factorial(n))

Submission status: Wrong Answer

Solution code:
import sys
import itertools
import numpy as np

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

N = I()
basho = [LI() for _ in range(N)]
keiros = list(itertools.permutations(range(1,N+1)))
nagasa = []

for keiro in keiros:
    
    diff = 0
    for i in range(1,len(keiro)):
        
        diff += (((basho[keiro[i]-1][0] - basho[keiro[i-1]-1][0]) ** 2) + ((basho[keiro[i]-1][1] - basho[keiro[i-1]-1][1]) ** 2))
        
    nagasa.append(diff)

num = np.array(nagasa)
print(np.average(num))

Submission status: Wrong Answer

Solution code:
import math
import itertools

def l2(z1, z2):
  return math.sqrt(pow(z1[0] - z2[0], 2) + pow(z1[1] - z2[1], 2))

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

dist = 0
z_fr = []
z_to = []
for seq in itertools.permutations(l, n):
  for z in seq:
    z_fr = z_to
    z_to = z
    if len(z_fr)==0:
      continue
    dist += l2(z_fr, z_to)

print(dist/math.factorial(n))

Submission status: Wrong Answer

Solution code:
from math import hypot, factorial


def dfs(p):
    res = 0
    for i in range(n):
        if used[i]:
            continue
        used[i] = True
        c = hypot(x[i] - x[p], y[i] - y[p]) if ~p else 0
        res += dfs(i) + c
        used[i] = False
    return res


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

used = [False] * n
ans = dfs(-1) / factorial(n)

print(ans)

Submission status: Wrong Answer

Solution code:
import sys

# import math
import heapq

# input = sys.stdin.readline
from collections import deque


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

    for i in range(N):
        for j in range(N):
            if i==j:
                continue
            ans += ((X[i]-X[j])**2 + (Y[i]-Y[j])**2 )**0.5

    print(ans/3)




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import itertools, math

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

numbers = 1
for i in range(1,n+1):
    numbers *= i
print(numbers)
#nの階乗

route = list(itertools.permutations(point))

d = 0

for pattern in route:
    for i in range(n-1):
        d += math.sqrt((pattern[i][0]-pattern[i+1][0])**2 + (pattern[i][1]-pattern[i+1][1])**2)
        

ans = d / numbers

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(n-1):
    for j in range(i+1,n):
        x1,y1=xy[i]
        x2,y2=xy[j]
        ans+=((x1-x2)**2+(y1-y2)**2)**(1/2)
N,N2=1,1
for i in range(1,n+1):
    N*=i
    if i<=n-2:
        N2*=i
if n==2:
    N2=0
print(ans*(N-N2*2)/N)

Submission status: Wrong Answer

Solution code:
from itertools import permutations
N = int(input())
xy = [tuple(map(int,input().split())) for _ in range(N)]
city = list(permutations(xy))
all_len = 0
for i in city:
  sum_len = 0
  for j in range(1,N):
    sum_len += ((i[j][0]-i[j-1][0])**2 +(i[j][1]-i[j-1][1]))**0.5
  all_len += sum_len
print(all_len/len(city))

Submission status: Wrong Answer

Solution code:
#<100q.順列全探索>
#<15>
from itertools import combinations
n = int(input())
town = []
for i in range(n):
    x, y = map(int,input().split())
    town.append((x,y))

ans = 0
for i, j in combinations(town, 2):
    print(i, j)
    ans += ((i[0] - j[0]) ** 2 + (i[1] - j[1]) ** 2) ** (0.5)
print(2 * ans / n)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for _ in range(n):
  l.append(list(map(int, input().split())))
#print(l)
import itertools
d=len(list(itertools.permutations(l)))/2
cnt=0
fin=[]
for v in itertools.permutations(l):
  if cnt==d:
    break
  else:
    cnt+=1
    chk=[]
    for z in range(len(v)-1):
      chk.append(((v[z][0]-v[z+1][0])**2+(v[z][1]-v[z+1][1])**2)**0.5)
    fin.append(sum(chk))
print(sum(fin)/len(fin))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for _ in range(n):
  l.append(list(map(int, input().split())))
#print(l)
import itertools
d=len(list(itertools.permutations(l)))/2
cnt=0
fin=[]
for v in itertools.permutations(l):
  if cnt==d:
    break
  else:
    cnt+=1
    chk=[]
    for z in range(len(v)-1):
      chk.append(((v[z][0]-v[z+1][0])**2+(v[z][1]-v[z+1][1])**2)**0.5)
    fin.append(sum(chk))
    print(fin)
print(sum(fin)/len(fin))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[]
for _ in range(n):
  l.append(list(map(int, input().split())))
#print(l)
import itertools
d=len(list(itertools.permutations(l)))/2
cnt=0
chk=[]
for v in itertools.permutations(l):
  if cnt==d:
    break
  else:
    cnt+=1
    for z in range(len(v)-1):
      chk.append(((v[z][0]-v[z+1][0])**2+(v[z][1]-v[z+1][1])**2)**0.5)
print(sum(chk)/len(chk))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from itertools import permutations
N=int(input())
town=[]
for i in range(N):
    x,y=map(int,input().split())
    town.append((x,y))

ans=0
for i,j in permutations(town,2):
    ans+=(((i[0]-j[0])**2+(i[1]+j[1])**2)**0.5)
print(ans/N)

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
#print(x)
path_length = 0
cnt = 0
import itertools
for p in itertools.permutations(x):
    #print(p, p[1:])
    for (x1,y1), (x2,y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
        cnt += 1
print(path_length/(cnt))

Submission status: Wrong Answer

Solution code:
n = int(input())
x = []
for i in range(n):
    a = list(map(int,input().split()))
    x.append(a)
#print(x)
path_length = 0
import itertools
for p in itertools.permutations(x):
    #print(p, p[1:])
    for (x1,y1), (x2,y2) in zip(p, p[1:]):
        path_length += ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** .5
print(path_length/(n*2))

Submission status: Wrong Answer

Solution code:
import itertools
n=int(input())
l=[tuple(map(int,input().split())) for _ in range(n)]
p=itertools.permutations(l,4)
ans=0
for a1,a2,a3,a4 in p:
    b1=(a1[0]-a2[0])**2+(a1[1]-a2[1])**2
    b2=(a3[0]-a4[0])**2+(a3[1]-a4[1])**2
    b3=(a1[0]-a4[0])**2+(a1[1]-a4[1])**2
    b4=(a2[0]-a3[0])**2+(a2[1]-a3[1])**2
    if b1==b2 and b3==b4:
        ans=max(b1,ans)
print(ans)

Submission status: Wrong Answer

Solution code:


from itertools import permutations
from math import hypot, factorial

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,y1,x2,y2: ((x1-x2)**2 + (y1-y2)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / factorial(n))

Submission status: Wrong Answer

Solution code:


from itertools import permutations
from math import hypot, factorial

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,x2,x3,x4: ((x1-x3)**2 + (x2-x4)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / factorial(n))

Submission status: Wrong Answer

Solution code:

from itertools import permutations
from math import hypot, factorial

n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
d = lambda x1,x2,x3,x4: ((x1-x2)**2 + (x3-x4)**4)**0.5

x = 0
for i in permutations(a):
	for j in range(n-1):
		x += d(i[j][0],i[j][1], i[j+1][0],i[j+1][1])

#for i in range(n): f*=i+1
print(x / factorial(n))

Submission status: Wrong Answer

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

a = np.zeros((N, 2))
kyori = np.zeros(int(N*(N-1)/2))

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


count=0
for i in range(0,N-1):
    for j in range(i+1,N):
     kyori[count]=math.sqrt((a[i][0]-a[j][0])**2+(a[i][1]-a[j][1])**2) 
     count=count+1
  
print(kyori)
print(2*sum(kyori)*(N-1)*math.factorial(N-2)/math.factorial(N))

Submission status: Wrong Answer

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

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

if n == 2:
    print(ans)
else:
    print(ans*(n-1)/n)