【水题】

/*Vive la Difference! 
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 306    Accepted Submission(s): 208


Problem Description
Take any four positive integers: a, b, c, d. Form four more, like this:

|a-b| |b-c| |c-d| |d-a|

That is, take the absolute value of the differences of a with b, b with c, c with d, and d with a. (Note that a zero could crop up,
 but they’ll all still be non-negative.) Then, do it again with these four new numbers. And then again. And again. Eventually,
  all four integers will be the same. For example, start with 1,3,5,9:
1 3 5 9
2 2 4 8 (1)
0 2 4 6 (2)
2 2 2 6 (3)
0 0 4 4 (4)
0 4 0 4 (5)
4 4 4 4 (6)
In this case, the sequence converged in 6 steps. It turns out that in all cases, the sequence converges very quickly. In fact, it can be shown
 that if all four integers are less than 2^n, then it will take no more than 3*n steps to converge!
Given a, b, c and d, figure out just how quickly the sequence converges.
 

Input
There will be several test cases in the input. Each test case consists of four positive integers on a single line 
(1 ≤ a,b,c,d ≤ 2,000,000,000), with single spaces for separation. The input will end with a line with four 0s.
 

Output
For each test case, output a single integer on its own line, indicating the number of steps until convergence. Output no extra spaces, and do not separate answers with blank lines.
 

Sample Input
1 3 5 9
4 3 2 1
1 1 1 1
0 0 0 0
 

Sample Output
6
4
0
 

Source
SER2011 
*/
#include<stdio.h>
#include<stdlib.h>
int main()
{
	int a, b, c, d, num;
	while(scanf("%d%d%d%d", &a, &b, &c, &d) != EOF && (a || b  || c || d) )
	{
		int k ;
		num = 0;
		while( 1 )
		{
			k = a;
			if( a == b && b == c && c == d)
			break;
			a = abs(a - b);
			b = abs(b - c);
			c = abs(c - d);
			d = abs(d - k);
			num++;	
		}
		printf("%d\n", num);
	}
	return 0;
}

题意:给出四个数,要求取任意2个数之间的绝对值,得到的新的四个数如果不相同则继续上一部操作,求总共经过了几次操作。

思路:模拟即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值