Advertisement
steverobinson

Puzzle: Tails all the way

Mar 23rd, 2011
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. Question: 1 : Tails all the way
  2. ----------------------------------
  3. Problem code: TAILS
  4.  
  5. John and James planned to play a game with coins. John has 20 coins and he places it on the table in a random manner(i.e either with heads(1) or tails(0) facing up). John asked james to convert all heads into tails in minimum number of flips with the condition that if a coin is flipped the coins present to the right and left of the chosen coin should also be flipped.
  6.  
  7. Input
  8.  
  9. A single line with 20 space-separated integers
  10.  
  11. Output
  12.  
  13. The minimum number of coin flips necessary to convert all heads into tails (i.e., to 0). For the inputs given, it will always be possible to find some combination of flips that will manipulate the coins to 20 tails.
  14.  
  15. Example
  16.  
  17. Input:
  18. 0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0
  19.  
  20. Output:
  21. 3
  22.  
  23. Hint
  24. Explanation of the sample:
  25.  
  26. Flip coins 4, 9, and 11 to make them all tails:
  27. 0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 [initial state]
  28. 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 [after flipping coin 4]
  29. 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 [after flipping coin 9]
  30. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [after flipping coin 11]
  31.  
  32. <<<---No solution Found--->>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement