algorithm - Partitioning square root of natural numbers into two sets for closest sum? -


I got stuck on this problem for a while. It asks to divide the square root of numbers from 1 to N into two sets, A and B, as in the set A, the number of numbers in the set B is as close as possible to the sum of the numbers. I have tried very hard, but I am unable to come up with an algorithm.

  • imigen n numbers (actual number) non -According to the case, which is your case. sqr (n) will always be greater than sqr (n - 1) .

  • Specify the list.

  • Create 4 variables, setA , setB as empty array, and sumA , SumB has been started with the number 0.

  • Select the value from the back list and add it to setA and sumA .

  • Include and attach to the remaining reversal index & amp; Add to set & amp;

From the top of my head:

  F (divide_in_2_groups) & lt; - set (set) setA, setB = [] sumA, sumB = 0 addA, list [0] sumA  

Comments