Python--ZOJ1067

ZOJ1067

这道题对RGB的表述可以理解成三维坐标下求最短距离的,先输入16个点,再任意输入n个点(-1 -1 -1 表示结束)求与16个点中距离最短的点。

#2015-02-10
# -*- coding: utf-8 -*-
import math

ip1 = [[] for j in range(16)]
ip2 = [[]]
count = 0
while count < 16:
    ip = raw_input()
    ip1[count] = ip.split()
    count += 1
    
ip = raw_input()
ip = ip.split()
count = 0
while int(ip[0])!=-1 and int(ip[1])!=-1 and int(ip[2])!=-1:
    ip2.append(ip)
    ip = raw_input()
    ip = ip.split()
    count += 1
    
key = 1
while key <= count:
    flag = 10000000
    j = 0
    for i in range(16):
        a = int(ip2[key][0])
        b = int(ip2[key][1])
        c = int(ip2[key][2])
        a1 = int(ip1[i][0])
        b1 = int(ip1[i][1])
        c1 = int(ip1[i][2])
        d = math.sqrt((a-a1)**2+(b-b1)**2+(c-c1)**2)
        if d < flag:
            flag = d
            j = i
    print '(%d,%d,%d) maps to (%d,%d,%d)' % (int(ip2[key][0]),int(ip2[key][1]),int(ip2[key][2]),int(ip1[j][0]),int(ip1[j][1]),int(ip1[j][2]))
    key += 1
        
    

这里要用到sqrt()函数,需要先导入math。

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值