Find the amount of water in ith cup in a pyramid structure?

后端 未结 6 1579
猫巷女王i
猫巷女王i 2020-12-15 12:12

This question was asked in a forum. Any suggestions?

There is a pyramid with 1 cup at level , 2 at level 2 , 3 at level 3 and so on.. It looks something like this

6条回答
  •  清歌不尽
    2020-12-15 13:00

    Some ideas: (1) The important is knowing which two cups are inputs to the ith cup. (2) The important is know the Minimum Lleft that will bring you water from your left side and what level Lright will bring you water from your right side (3) So you need to know which cups provide water to cup ith. This is easier, thinking quick, if you start numbering from 0. Cup ith will fill (i-1)*2+1 and i*2, what means that cup kth will receive water from (for k%2=1) (k-1)/2 and (k+1)/2 (for k%2=0) k/2 and k/2+1 (4) With that you should check that for any L you will calculate the difference L-Lleft and L-Lright. When positive the water provided is the result of dividing by 2^n the calculated difference, where n is the level of the cup.

提交回复
热议问题