算法题 求三个圆的等视角点
来源:互联网 发布:利用淘宝规则赚钱 编辑:程序博客网 时间:2024/06/04 19:15
京东算法岗考了的一道算法题
另一个博客上有个详细的描述:http://blog.csdn.net/snowy_smile/article/details/50131317
内容:
那篇文章中给出了C代码。
自己用的python写的,放上来python代码。
import mathdef corner(x,y,o_x,o_y,r): #sin value dis=math.sqrt((x-o_x)**2 + (y-o_y)**2) return r/disdef cost_func(ang): #cost function, ang is a three dimension vector result=0 for i in range(3): result+=(ang[i]-ang[(i+1)%3])**2 return resultdef cal_cost(x,y,three_point): ang=[] for i in range(3): cor=corner(x,y,three_point[i][0],three_point[i][1],three_point[i][2]) ang.append(cor) return cost_func(ang)flag = 0while 1: if flag==1: break #save data(x,y,r) input_list=[] for _ in range(3): s = raw_input().split() if s==[]: flag=1 break x,y,r = int(s[0]),int(s[1]),int(s[2]) input_list.append((x,y,r)) #init center_x = sum([x[0] for x in input_list])/3 center_y = sum([x[1] for x in input_list])/3 evr = cal_cost(center_x,center_y,input_list) #move vector dx = (-1,0,1,0) dy = (0,-1,0,1) step = 1 for _ in xrange(10**6): for i in range(4): x = center_x + step * dx[i] y = center_y + step * dy[i] new_cost=cal_cost(x,y,input_list) if new_cost< evr: center_x=x center_y=y evr=new_cost break else: step=step/2 if step<= 10**(-6): break print center_x,center_y
0 0
- 算法题 求三个圆的等视角点
- 【Codeforces Beta Round 2C】【计算几何 转化 模拟退火】Commentator problem 求一个点,使得该点到三个圆的视角范围尽可能接近
- 比特币的三个视角
- 已知矩形的任意三个点,求第四个点
- 求最大公约数和最小公倍数的三个算法
- 已知圆上的三个点求此圆的周长
- java写的三个求乘法逆元的算法
- 求最近点对的基础算法
- 求直线上的整数点算法
- 求 三个数中最大值 的几种灵活算法
- 过三点的圆 用鼠标点三个共线的点 生成过这三个点的外接圆 源代码
- 求圆的等数据
- 有多个点,求任意三个点组成的三角形的外接圆的最大半径
- 求给出三个坐标点所围成的三角形的高
- 求内切圆的圆心和半径(已知三个点的坐标)
- 求内切圆的圆心和半径(已知三个点的坐标)
- C++里已知三个三维点,求他们的平面方程,怎么做?
- C、C++和JAVA等程序语言中,函数参数三个点“...”的意思和用法。
- Linux下搭建个人网站
- 数据结构(一) 线性表、栈和队列
- Android内存优化(使用SparseArray和ArrayMap代替HashMap)
- VMware Workstation上安装Ubuntu 16.04 Server中文版报错:“无法安装busybox-initramfs”
- 求字符串中出现次数最多的字母及次数
- 算法题 求三个圆的等视角点
- 分分钟学会RxAndroid的使用(一)
- SPOJ 694 Distinct Substrings 后缀数组
- spring mvc配置
- 二叉搜索树的后序遍历序列
- 引用作为函数返回值
- ReactNative-Switch开关组件
- 我的出题记录
- LeetCode 127 Word Ladder