0
0

More than 1 year has passed since last update.

ABC57 B - Checkpoints diff 茶を解いた

Posted at

abc57_1.png
abc57_2.png
abc57_3.png
abc57_4.png
abc57_5.png

全探索ではなかろうか。
N,M が 50 以下なので行けそうな気配。

Checkpoints.py
N,M = map(int,input().split())

person = []
for _ in range(N):
    a,b = map(int,input().split())
    person.append([a,b])

checkPOINT = []
for _ in range(M):
    c,d = map(int,input().split())
    checkPOINT.append([c,d])

nums = []
memo = 0
#print(person,checkPOINT)
for n in range(N):
    score,ans = 0,float("inf")
    for m in range(M):
        #print(n,m)
        score = abs(person[n][0]-checkPOINT[m][0]) + abs(person[n][1]-checkPOINT[m][1])
        if score < ans:#<= 最初に最小値となったものを記録し続ける <= ココ
            ans = score
            memo = m+1
    nums.append(memo)

for s in nums:
    print(s)

問題文には最小地点が複数の場合、
チェックポイントの数字が一番小さい場合を所望している。
前述のコメントにある ここ にあるような書き方で OK

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