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

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

Автор dualthread, история, 5 часов назад, По-английски

Hey guys, just wanna share my approach and wanna know your way of doing them!

Problem A: Walk the Line

Quite a famous puzzle, sorting the array and the traveller with min element always takes others to other end.

Problem B: Line by Line

lets say probability is x (p/100), for the n-1 lines, total prob. is x^(n-1) and lets say we have y as the increased prob. so y^n = x^(n-1) => y = x^(1-1/n). So our increase is p — y*100. (Use doubles)

Problem D1: Line of Delivery (Part 1)

As each of the stone can replace next stone and pass on the energy, the final positions will be the same as input energies. If 0 to i stones are thrown, the resulting positions will be sorted energies of 0 to i. So just sorting the array and indexing 1 from end works. Taking the upper or lower key with min difference for each G outputs ans.

Problem C: Fall in Line

Problem D2: Line of Delivery (Part 2)

If you guys solved problem C & D2, please let me know your approaches.

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

»
5 часов назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

C: Suppose you know that "a lot" of points are on one line (let's say, over half). Can you find a simple way of finding that line?

D2: The same observation as for D1 — we just need to find the final positions of the balls, because we know they will be in sorted order. Now suppose we already launched $$$k$$$ balls, and they have positions $$$a_1, \ldots, a_k$$$. A new ball comes in with energy $$$x$$$ — how does that affect the sequence? My hint is instead of looking at $$$a_i$$$, look at $$$b_i := a_i - i$$$ (assuming $$$a_i$$$ is sorted).

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

Zixiang Zhou (duality) solved d2 in interesting way, 2nd position on scoreboard, very short and simple, but I don't understand idea

  • »
    »
    61 минуту назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    It looks similar to my solution, the idea is that the sequence $$$a_i - i$$$ happens to be very easy to update.

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

      I try to understand the "meaning" of this value ai-I, looks like after that transformation the bricks are moving 1 step further, if not collided.

»
70 минут назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

For D2, I have an idea that is slightly different from the Official Solution.

Instead of keeping track of where the stones are, I keep track of where the spaces are.

Initially there are infinitely many spaces, from 0 to +inf. When a stone is thrown with energy E. The coordinate of the left most E + 1 + i spaces (i is the index of the stone, 0-based) will decrease by 1. For example, after a stone of energy 4 was thrown, the spaces are now at -1, 0, 1, 2, 3, 5, 6, 7, 8, .... If we again throw a new stone with energy 6, then the spaces are now at -2, -1, 0, 1, 2, 4, 5, 6, 8, 9, ....

Decreasing a prefix of the array can be time consuming, but we can transform this array into a new array that represent the difference between adjacent elements.

For example, -1, 0, 1, 2, 3, 5, 6, 7, 8, ... becomes -1, 1, 1, 1, 1, 2, 1, 1, 1, ...

and -2, -1, 0, 1, 2, 4, 5, 6, 8, 9, ... becomes -2, 1, 1, 1, 1, 2, 1, 1, 2, 1, ...

Decreaseing a prefix of the array becomes $$$O(1)$$$. Also, most of the entries have value 1, so we can only keep track of the positions where value isn't 1.

After we finish processing the spaces, we can easily reconstruct the position of these stones.

»
52 минуты назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

Here's a video where I explain my solutions, for anyone interested.