圓周上兩點距離


#!/bin/python
# -*- coding: UTF-8 -*-
import sys

"""搜狗題目,圓周上兩點距離,
第一行:輸入n(圓上的n個點) 第二行:輸入n個點的度數s(0<=s<=360) 雙精度,8位小數
輸出園中距離最遠的兩點之間的夾角度數m(0<=m<=180),雙精度,保留8位小數
"""
n = input()
circle = []
for i in range(n):
doublenum = sys.stdin.readline().strip()
doublenum = float(doublenum)
circle.append(doublenum)

"""二分查找尋找下屆,恰好小於key"""
def Binery_Find(circle,n,key):
low = 0
high = n-1
mid = (low + high) / 2
while low < high:
if circle[mid]< key :
low = mid
else:
high = mid -1
mid = (low + high+1) / 2
return mid
maxx = 0
for i in range(n-1):
key = circle[i]+180
if key > 360:
key -= 360
mid1 = Binery_Find(circle,n,key)
mid2 = mid1+1
if mid1< n-1:
maxx = max(circle[mid1]-circle[i],maxx,360-(circle[mid2]-circle[i]))
else:
maxx = max((circle[mid1] - circle[i]), maxx)
print "%.8f"%maxx

注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com