主要利用这段代码进行剪枝操作
if(a<b){
for(int j=0;j<=count;j++){
if(a==temp[j]){
cout<<“NO Solution!”;
return 0;
}
}
#include<iostream>
using namespace std;
#define NUM 100000
int main(){
static int a,b,count=0;
int *temp=new int[NUM];
temp[0]=0;
cout<<“a:”;
cin>>a;
cout<<“b:”;
cin>>b;
while(a!=b){
if(a>b){
a=a/2;
if(a<b){
for(int j=0;j<=count;j++){
if(a==temp[j]){
cout<<“NO Solution!”;
return 0;
}
}
temp[count+1]=a;
}
count++;
}
if(a<b){
a=a*3;
if(a<b){
for(int j=0;j<=count;j++){
if(a==temp[j]){
cout<<“NO Solution!”;
return 0;
}
}
temp[count+1]=a;
}
count++;
}
}
cout<<“次数:”<<count;
}