CHEF AND BALLS
Problem Description
Chef has bought ten balls of five colours. There are two balls of each colour. Balls of same colour have same weight. Let us enumerate colours by numbers from 1 to 5. Chef knows that all balls, except two (of same colour), weigh exactly one kilogram. He also knows that each of these two balls is exactly 1 kg heavier than other balls.You need to find the colour which balls are heavier than others. To do that, you can use mechanical scales with two weighing pans. As your scales are very accurate, you can know the exact difference of weights of objects from first and second pans. Formally, the scales will give you the difference (signed difference) of weights of the objects put into the first pan and the second pan. See the following examples for details
If you put two balls of the same colour on your scales, each ball to one pan, the scales will tell you that difference is "0".
But if you put into the first pan some balls of total weight 3 kg, and into the second pan of 5 kg, then scales will tell you "-2" because the second pan is 2 kg heavier than first
Similarly, if you put 5 kg weight in first pan and 3 kg in the second pan, then scale will tell you "2" as first pan is 2 kg heavier than second.
Input & Output
The interaction process have two phases. At first phase you perform sequence of weighings on the mechanical scales. At the second phase you should output the colour of the heavier balls
To use the mechanical scales, you should print "1"(without quotes) and then print two lines, the first line will describe the enumeration of colours of balls on the first pan and second line should that of second pan
To describe some pan, you need to print one integer n - the number of balls you put in this pan, followed by n space-separated integers - colours of the balls you put in this pan
Once you have printed required data, you can read from the standard input one integer - the difference of weights of the first and the second pans
To output the colour of the heavier balls, you should print "2"(without quotes) and one integer in next line - colour of the heavier balls.
Constraints
Each colour you print should be between 1 and 5.
CODING ARENA
#include<stdio.h>
int main()
{
int x;
scanf("%d", &x);
if(x==1)
{
printf("1\n3 1 2 2\n3 3 4 4\n2\n1");
}
else
{
printf("1\n3 1 2 2\n3 3 4 4\n2");
}
return 0;
}
Test Case 1
Input (stdin)1
Expected Output
1
3 1 2 2
3 3 4 4
2
1
Test Case 2
Input (stdin)3
Expected Output
1
3 1 2 2
3 3 4 4
2
No comments:
Post a Comment