The task itself is as follows:

There are 3n coins, among which there is a fake (heavier than all the others). It is required to determine the number of a counterfeit coin using weights without weights with exactly n weighings. The user enters 0 if the balance is balanced.

  1. If outweighed the left bowl.
  2. If outweighed the right bowl.

After each entry, 0, 1, or 2 outputs the new intervals of the array. I do not know how to organize a function so that it divides the array into 3 parts.

for (int i = 0; i <=1*p/3; i++) { arr1[i]=arr[i]; } for (int i = 1*p/3; i <=2*p/3; i++) { arr2[i]=arr[i]; } for (int i = 2*p/3; i <=p; i++) { arr3[i]=arr[i]; } 
  • one
    Can't arrange input 0.1 or 2? copying an array is usually done like this: #include <algorithm> // .... int a_len = p / 3; std :: copy (arr, arr + a_len, arr1); std :: copy (arr + a_len, arr + a_len * 2, arr2); std :: copy (arr + a_len * 2, arr + a_len * 3, arr3); more beautiful and easier. and std::vector better to replace. - KoVadim
  • Do I need to copy the array? Moreover, do we need an array at all? Hint: An array is designed to store values. But we have no values, we only have intervals, which in the process converge to a single index. - insolor

0