Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя Hando

Автор Hando, история, 19 месяцев назад, По-английски

It is an interactive problem.

We have an array $$$a$$$ that we don't know ( and cannot modify ) and we are given an array $$$b$$$ of the same size as $$$a$$$. (length of $$$a$$$ is less then $$$4\ 000$$$).

We need to arrange the elements in the array $$$b$$$ such that the cross product of arrays $$$a$$$ and $$$b$$$ is maximal. ($$$a_1 \ * b_1 \ + \ ... \ + \ a_n \ * b_n$$$ is maximal ).

The interaction consist in giving the array $$$b$$$ and reciveing the cross product with $$$a$$$ every time. (You cannot give an array that is not a permutation of the inital array the we are given $$$b$$$.)

How can we find a rearrangement of array $$$b$$$ that gives the maximal cross product with $$$a$$$, in less than $$$6\ 000$$$ tries?

Edit: I think it is important to mention that $$$a$$$ and $$$b$$$ can have any positive ($$$ > 0$$$) value (and they do not need to be a permutation of $$$n$$$ elements necessarly).

Edit: Also i believe that that jtrh has the right solution, it just needs a little bit of casework when we have in $$$b$$$ multiple elements equal to $$$b[0]$$$ (but I think you can figure out what to do next). My thanks!

Also, thank you to everyone who commented!

  • Проголосовать: нравится
  • +11
  • Проголосовать: не нравится

»
19 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Is it necessary to pass B every time with its own same elements?.Like we can just pass something like [1,0,0,0] then [0,1,0,0] then [0,0,1,0] then [0,0,0,1] and every time cross product which we get will be the value of element at that index in array a.When we know a now we can just sort them accordingly and find the value.

  • »
    »
    19 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    I think the problem forces you to use permutations of $$$b$$$. To find the ordering of $$$a$$$ we can find the difference $$$a[i]-a[j]$$$ by subtracting the product of $$$b$$$ after swapping $$$i$$$ and $$$j$$$ from the product of the original $$$b$$$ and then divide the result by $$$b[i]-b[j]$$$:

    $$$\frac{(a[i]*b[i]+a[j]*b[j])-(a[i]*b[j]+a[j]*b[i])}{b[i]-b[j]}=\frac{a[i]*(b[i]-b[j])+a[j]*(b[j]-b[i])}{b[i]-b[j]}=\frac{(b[i]-b[j])*(a[i]-a[j])}{b[i]-b[j]}=a[i]-a[j]$$$.

    I would probably fix $$$j=0$$$ to get the difference array $$$c[i]=a[i]-a[0]$$$ then sort from there.