0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AtCoder B - Good Distance

Posted at

問題

N, D = map(int,input().split()) 
#リスト内包表記
#上から順にlistを読み込んでlistに格納していく。
x = [list(map(int, input().split())) for l in range(N)]

ans = 0

for i in range(N-1): # i番目の点
  for j in range(i+1, N): # j番目の点
        dist = 0
        for k in range(D): #i点とj点を計算
            dist += (x[i][k] - x[j][k]) ** 2
        if dist ** 0.5 == int(dist ** 0.5):
            ans += 1
            
print(ans)

ポイント

i点とj点を比較するので、全検索forの2重ループを使用する。
距離を測る際には別にfor文を用意する必要がある。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?