Change the ball
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 479 Accepted Submission(s): 166
Problem Description
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?
Garfield is not able to estimate the minimal steps to achieve the aim. Can you tell him?
Input
For each line, there are three intergers Y, B, R(1<=Y,B,R<=1000),indicate the number refered above.
Output
For each case, tell Garfield the minimal steps to complete the assignment. If not, output the symbol “):”.
Sample Input
1 2 3 1 2 2
Sample Output
): 2
Source
Recommend
题目大意:就是他有r个红球,b个蓝球,y个黄球,两个不同颜色的球放在一起,后变成剩下的那种颜色,他想把所有的球都变成一种颜色,问需要多少步,
思路:当有两个球相等时,
绝对可以,当有一个比另一大三的倍数也可以,想想就好
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int a[5];
while(scanf("%d%d%d",&a[1],&a[2],&a[3])!=EOF)
{
qsort(a+1,3,sizeof(a[1]),cmp);
if(a[1]==a[2]||(a[2]-a[1])%3==0)
printf("%d\n",a[2]);
else
if(a[3]==a[1]||a[2]==a[3]||(a[3]-a[2])%3==0||(a[3]-a[1])%3==0)
printf("%d\n",a[3]);
else
printf("):\n");
}
}
绝对可以,当有一个比另一大三的倍数也可以,想想就好
ac代码
#include<stdio.h>
#include<stdlib.h>
int cmp(const void *a,const void *b)
{
return *(int *)a-*(int *)b;
}
int main()
{
int a[5];
while(scanf("%d%d%d",&a[1],&a[2],&a[3])!=EOF)
{
qsort(a+1,3,sizeof(a[1]),cmp);
if(a[1]==a[2]||(a[2]-a[1])%3==0)
printf("%d\n",a[2]);
else
if(a[3]==a[1]||a[2]==a[3]||(a[3]-a[2])%3==0||(a[3]-a[1])%3==0)
printf("%d\n",a[3]);
else
printf("):\n");
}
}