void Circle::Backtrack( int t)
{
if (t>n) Compute();
else
for ( int j = t; j <= n; j++) {
Swap(r[t], r[j]);
float centerx =Center(t);
if ( centerx+r [t]+r[1]<min)
{// 下界約束
x[t]= centerx ;
Backtrack(t+1);}
Swap(r[t], r[j]);}
}
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]);
if ( valuex >temp) temp= valuex ;
}
return temp;
}
void Circle::Compute(void)
{// 計算當前圓排列的長度
float low=0,
high=0;
for ( int i =1;i<= n;i ++) {
if (x[ i ]-r[ i ]<low) low=x[ i ]-r[ i ];
if (x[ i ]+r[ i ]>high) high=x[ i ]+r[ i ];
}
if (high-low<min) min=high-low;
}
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
