Advertisement

算法设计与分析 | 回溯法 | 圆排列问题

阅读量:
复制代码
    #include<iostream>
    #include<math.h> 
    using namespace std;
    class Circle
    {
    	public:
    		float Center(int t);
    		void Compute(void );
    		void BackTrack(int t);
    		
    		float min;  	//当前最优值 
    		float *x;		//当前圆排列圆心横坐标 		
    		float *r;		//当前圆排列 
    		float *result;  //记录最终 的圆半径排序 
    		int n;			//待排列圆的个数 
    };
    float Circle::Center(int t)//计算当前所选圆的圆心横坐标 
    {
    	float temp = 0;//记录临时的圆心的横坐标
    	 for(int j=1;j<t;j++)
    	 {
    	 	float valuex = x[j]+2.0*sqrt(r[t]*r[j]);
    		 //算一下前面所有的圆心到目前第T个圆的圆心的距离 
    		 //因为可能这里有陷阱 
    		 if(valuex >

全部评论 (0)

还没有任何评论哟~