我上个 不知道正确不 楼主也不给地址
程序代码:
#include <stdio.h>
#define N 10000
int judge(int a[], int n, int m)
{
int i;
for (i = 0; i < n; i++)
if (m == a[i])
return 1;
return 0;
}
int status(int a[N], int n, int b[N])
{
int i, j = 0;
for (i = 0; i < n; i++)
{
b[j++] = a[i] - 1;
b[j++] = a[i] + 1;
b[j++] = 2 * a[i];
}
return j;
}
int main(void)
{
int a[N] , b[N] , c[N];
int cow, man, count = 0;
int len, len1, len2, i;
for(i = 0; i < N; i++)
{
a[i] = b[i] = c[i] = 0;
}
while(EOF != scanf("%d%d",&man, &cow))
{
if(man >= cow)
{
printf("%d\n", man - cow);
}
else
{
while(1)
{
count = 0;
a[0] = man;
len = 1;
count++;
while(1)
{
len1 = status(a, len, b);
if (judge(b, len1, cow))
break;
count++;
len2 = status(b, len1, c);
if (judge(c, len2, cow))
break;
count++;
len = status(c, len2, a);
if (judge(a, len, cow))
break;
count++;
}
printf("%d\n", count);
break;
}
}
}
return 0;
}