算法出现传不进去参数的问题(警告)
#include "stdafx.h"
#include"stdio.h"
#include"conio.h"
int zhao(int coin[],int low,int high)//定义判断质量轻重函数
{
int i,sum1 =0 ,sum2 = 0,sum3 = 0;
if(low+1 == high )//数量为2时
{
if(coin[low]<coin[high])
return low+1;
else
return high+1;
}
/*数量为偶数时*/
if((high - low +1) % 2 == 0)
{
for(i = low; i<=low+(high-low) / 2; i ++)//循环求取前半段的和
sum1 = sum1 + coin[1];
for(i=low +(high - low) / 2 + 1;i<=high;i++)//循环求取后半段的和
sum2 = sum2 +coin[i];
/*比较两端和的大小并返回小的*/
if(sum1 < sum2)
return (zhao(coin,low,low+( high - low ) / 2 ));//递归调用
if(sum1 > sum2)
return (zhao(coin,low+( high - low ) / 2, high ));//递归调用
}
/*数量为奇数时*/
if((high - low +1) % 2 != 0)
{
for(i = low; i<=low+(high-low) / 2; i++)//循环求取前半段的和
sum1 = sum1 + coin[1];
for( i = low + (high - low) / 2 + 1;i<=high;i++)//循环求取后半段的和
sum2 = sum2 +coin[i];
sum3=coin[low+(high-low)/ 2];
if(sum1 < sum2)
return (zhao(coin,low,low+( high - low ) / 2 ));
if(sum1 > sum2)
return (zhao(coin,low+( high - low ) / 2, high ));
if(sum1+sum3==sum2+sum3)
return (low+(high-low)/2+1);
}
}
int _tmain(int argc, _TCHAR* argv[])
{
int coin[30] ={1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
printf("结果是%d",zhao(coin,0,29));
getchar();
return 0;
}
[解决办法]
没看懂你代码什么意思
大概看了下。。。明显的问题有一个
求前半段的和
sum1 = sum1 + coin[1];
sum1 = sum1 + coin[i];