Last active
August 10, 2017 07:36
-
-
Save ryu1-1uyr/a01d85380eb52f57cc9be008a23c2707 to your computer and use it in GitHub Desktop.
paiza.jp/poh/phantom_thief の問題。座標上の点間を最短距離で詰める。行き詰まった 悪くないです ループ部分が課題
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import math | |
nums = int(input()) | |
distance = 0 | |
distance2 = 0 | |
this_x = 0 | |
this_y = 0 | |
x_y ='' | |
data = {} | |
sortdata = [] | |
#inputするための場所 | |
for i in range(nums): | |
[x,y] = map(int, input().split()) | |
distance = math.hypot(x, y) | |
x_y = str(x)+' '+str(y) | |
data[distance] = x_y | |
sortdata = sorted(data) | |
print(data[sortdata[0]]) | |
for i in range(nums -1): | |
[this_x, this_y] = map(int,data[sortdata[0]].split())#座標移動 | |
if i == 0: | |
del data[sortdata[0]] | |
del sortdata[0] | |
if len(sortdata) == 1: | |
print(data[sortdata[0]]) | |
break | |
[x, y] = map(int,data[sortdata[0]].split()) | |
[x2, y2] = map(int,data[sortdata[1]].split()) | |
x = x - this_x | |
y = y - this_y | |
x2 = x2 - this_x | |
y2 = y2 - this_y | |
distance = math.hypot(x,y) | |
distance2 = math.hypot(x2,y2) | |
if distance <= distance2: | |
x = x + this_x | |
y = y + this_y | |
print(x,y) | |
del sortdata[0] | |
elif distance2 < distance: | |
x2 = x2 + this_x | |
y2 = y2 + this_y | |
print(x2,y2) | |
del sortdata[1] | |
#del data[sortdata[0]] | |
#del sortdata[0] | |
#sortdata = sorted(data) | |
#print(data[sortdata[0]]) | |
#outputするための場所 | |
#for i in range(nums): | |
# print(data[sortdata[i]]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment