两边一次移动到与b挨着则最短移动距离,每次移动一个位置则为最长移动距离。
int* numMovesStones(int a, int b, int c, int* returnSize){
//int answer[2]={0};
int *answer = (int *)malloc(sizeof(int) * 2);
int minimum_moves=0, maximum_moves = 0;
int aa = a, bb = b, cc = c;
if (a == b || a == c || b == c)
return 0;
if (a>b || a>c || b>c)
return 0;
//a右移
a++;
if (a != b)
{
minimum_moves++;
}
c--; //c左移
if (c != b)
{
minimum_moves++;
}
answer[0] = minimum_moves;
aa++;
if (aa != bb)
{
aa--;
maximum_moves = bb - aa - 1;
}
cc--; //c左移
if (cc != bb)
{
cc++;
maximum_moves = maximum_moves+(cc - bb - 1);
}
answer[1] = maximum_moves;
printf("%d %d",answer[0],answer[1]);
return answer;
}
int _tmain(int argc, _TCHAR* argv[])
{
int s=0;
numMovesStones(1, 2, 5, &s);
return 0;
}