找硬币(分治法)

/*现有16枚外形相同的硬币,其中有一枚比真币的重量轻的假币, 若采用分治法找出这枚假币,至少比较多少次才能够找出该假币*/ #include using namespace std; //我们假设16枚硬币的编号为0~15 int num=0; int weight(int a[],int start,int end) { int sum=0; for(int i=start;i<=end;i++) sum+=a[i]; return sum; } void findFalseCoin(int a[],int low,int high,int &coin) { int partion; partion=(low+high)/2; coin=partion; num++; if(low
原文地址:https://www.cnblogs.com/phoenixzq/p/1880355.html