PythonでJOI難易度5を埋める #8
考えたこと
全探索するだけ。実行時間も10secもあるので雑な全探索でも耐えます。
disという配列に探したい星座の星間の距離を入れて、見えている全ての星に対してそれぞれ調べます。
m = int(input()) targets = [list(map(int,input().split())) for _ in range(m)] n = int(input()) stars = [list(map(int,input().split())) for _ in range(n)] dis = [] for i in range(m): dis.append([targets[i][0] - targets[0][0],targets[i][1] - targets[0][1]]) for i in range(n): cnt = 0 cen_star_x, cen_star_y = stars[i][0], stars[i][1] #中心に考える星 for j in range(m): next_star_x = cen_star_x + dis[j][0] next_star_y = cen_star_y + dis[j][1] next_star = [next_star_x,next_star_y] if next_star in stars: cnt += 1 if cnt == m: print(cen_star_x - targets[0][0],cen_star_y - targets[0][1]) #移動した距離
PyPyを使うとTLEするので、Pythonを使いましょう。