The following is a statement of a programming problem i encountered I don't know how to solve it. Any ideas??
The owner of shop Jell Bells has order a large consignment of jell balls which is about to arrive. He has hired you as an assistant to help him sort the balls and put them in their respective containers at the shop (pretty simple ? HuH!!). Now the Job Profile Is : The balls are of different colors (say n), though many of the colors are repeated. Whenever the balls are removed from the consignment, they have to be kept in some temporary sack (say a stack) with each ball on top of other in no particular order. Each sack is of infinite capacity and you can use as many sacks as u like. When all the balls are removed from the consignment, they are then to be put in their respective colored containers at the store. Here comes the tricky thing, any colored container can be given to you by the owner to be filled. All the balls of that particular color have to be put in container at once. It may be possible that that particular colored ball is at the bottom of the sack, then you have to first move all the balls above it in some other sack. The owner wants that the number of temporary sacks multiplied by the number of moves is minimum. (How moves are counted when a ird move) and so on, then finally to the container (last move) for that particular ball). Once the things are sorted, you get your pay (and some jell balls too. Yummy!!) INPUT The first line of input contains an integer X, specifying the number of test cases. Second line contains number of containers N, and the number of balls M. the third line is the sequence in which the balls are removed from the consignment. Fourth is the order in which the owner of shop gives you the containers to be filled. OUTPUT The first line of output will be the number of moves P, and the number of sacks used Q. From second line onwards you have to specify each and every move as described in the example below. EXAMPLE Say the N colors are represented by numbers 1 to n, the temporary sacks as temp1, Sample input 1 3 6 3 3 2 2 1 1 1 2 3 Sample output 12 1 Move 1 :: put ball 3 in temp1 Move 2 :: put ball 3 in temp1 Move 3 :: put ball 2 in temp1 Move 4 :: put ball 2 in temp1 Move 5 :: put ball 1 in temp1 Move 6 :: put ball 1 in temp1 Move 7 :: put ball 1 in cont1 Move 8 :: put ball 1 in cont1 Move 9 :: put ball 2 in cont2 Move 10 :: put ball 2 in cont2 Move 11 :: put ball 3 in cont3 Move 12 :: put ball 3 in cont3 -------------------------------------------------------------------------------------------------------------------------------------------------------------------- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/algogeeks -~----------~----~----~----~------~----~------~--~---
