nyoj Change the ball 313 (技巧&思想)

Change the ball

时间限制: 3000 ms  |           内存限制: 65535 KB
难度: 3
描述
Garfield has three piles of balls, each pile has unique color of following: yellow, blue, and red. Now we also know Garfield has Y yellow balls, B blue balls, and R red balls. But Garfield just wants to change all the balls to one color. When he puts two balls of different color togather, the balls then change their colors automatically into the rest color. For instance, when Garfield puts a red one and a yellow one togather, the two balls immediately owns blue color, the same to other situations. But the rule doesn’t work when the two balls have the same color.
  Garfield is not able to estimate the minimal steps to achieve the aim. Can you tell him?
输入
For each line, there are three intergers Y, B, R(1<=Y,B,R<=1000),indicate the number refered above.
输出
For each case, tell Garfield the minimal steps to complete the assignment. If not, output the symbol “):”.
样例输入
2
1 2 3
1 2 2
样例输出
):
2
#include<stdio.h>
#include<string.h>
int tt(int a,int b,int t)
{
	t=a;a=b;b=t;
}
int main()
{
	int T,t;
	int a,b,c,d,e;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d",&a,&b,&c);
		d=e=0;
		if(a>b)
			tt(a,b,t);
		if(a>c)
			tt(a,c,t);
		if(b>c)
			tt(b,c,t);
		d=c-a;e=c-b;
		if(a==b||(b-a)%3==0)
			printf("%d\n",b);
		else if(b==c||(c-b)%3==0)
			printf("%d\n",c);
		else
			printf("):\n");
	}
	return 0;
}

你可能感兴趣的:(nyoj Change the ball 313 (技巧&思想))