PhoenixZq
分享是一门艺术~~
/*现有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
posted on 2010-11-18 01:57  PhoenixZq  阅读(707)  评论(0编辑  收藏  举报