Advertisement
Guest User

Untitled

a guest
Mar 8th, 2015
359
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Problem Statement
  2.     
  3. Fox Ciel just returned home from her trip to New Fox City. She has brought a bunch of souvenirs. You are given their values in a vector <int> value. Now she wants to give each souvenir either to her mother or to her father. She would like to divide the souvenirs in a fair way. More precisely:
  4. The total number of souvenirs given to her mother must be the same as the total number of souvenirs given to her father.
  5. At the same time, the total value of souvenirs given to her mother must be the same as the total value of souvenirs given to her father.
  6. Return "Possible" if she can reach her goal, and "Impossible" otherwise.
  7. Definition
  8.     
  9. Class:
  10. FoxAndSouvenirTheNext
  11.  
  12. Method signature:
  13. string ableToSplit(vector <int> value)
  14.  
  15. Limits
  16.     
  17. Time limit (s):
  18. 2.000
  19. Memory limit (MB):
  20. 256
  21. Stack limit (MB):
  22. 256
  23. Constraints
  24. -
  25. value will contain between 1 and 50 elements, inclusive.
  26. -
  27. Each element in value will be between 1 and 50, inclusive.
  28. Examples
  29. 0)
  30.  
  31.     
  32. {1,2,3,4}
  33. Returns: "Possible"
  34. One valid solution is to give the souvenirs with values 1 and 4 to her mother and the other two to her father. Each parent receives two souvenirs, and as 1+4 = 2+3, the total value is also the same for both parents.
  35. 1)
  36.  
  37.     
  38. {1,1,1,3}
  39. Returns: "Impossible"
  40. There is no valid solution. Note that {1,1,1} and {3} is not a valid way to split the souvenirs: even though the total value is the same, the number of souvenirs is not.
  41. 2)
  42.  
  43.     
  44. {1,1,2,3,5,8}
  45. Returns: "Possible"
  46. We have 1+1+8 = 2+3+5.
  47. 3)
  48.  
  49.     
  50. {2,3,5,7,11,13}
  51. Returns: "Impossible"
  52. The sum of values is an odd number, so it is impossible.
  53. 4)
  54.  
  55.     
  56. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48}
  57. Returns: "Possible"
  58.  
  59. 5)
  60.  
  61.     
  62. {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50}
  63. Returns: "Impossible"
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement