LoginSignup
1
0

More than 3 years have passed since last update.

【Atcoder】divertaB

Posted at

diverta全然出来なかった・・・:cloud_snow:
今日の問題はこちら

n個のボールをx,y座標でソートし、n個から2個選んだベクトルの中で最頻値のものは移動コストが0になるというもの。

解法

import collections
N = int(input())
if N == 1:
  print(1)
elif N == 2:
  print(1)
else:
  #入力
  ball = [tuple(map(int, input().split())) for _ in range(N)]
  #x,y座標でソート
  ball.sort(key=lambda x:(x[0], x[1]))
  #n個から2個選んだボールのそれぞれの対について、ベクトルを出力
  diff = [tuple((ball[i][0] - ball[j][0], ball[i][1] - ball[j][1])) for i in range(N) for j in range(i + 1, N)]
  c = collections.Counter(diff)
  #最頻のベクトルの個数をカウント
  ans = c.most_common()[0][1]
  print(N - ans)

精進します:angel_tone2:

1
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
1
0