Coding Practice Diary - Recursive C_stalls

in #coding6 years ago

Ballroom stalls

  1. f(x, y, k, a, b)
  2. first input f(1, 0, k, n, n+1)
  3. 1+0 >= k {return b}
  4. k -= x+y
  5. create map<LL,LL>m and add a--; m[a/2]+=x; m[a-a/2]+=x // offset of left & right respectively
  6. vector<pair<LL,LL>> v(m.begin(), m.end())
  7. return either a or b as t
  8. t-- //minus the location of last item it self and then use max, min to a/2 and a-a/2 respectively

Core:

m[(n-1)/2] += 1
m[n-1 - (n-1)/2] += 1

n[n/2] += 0
n[n/2] += 0

  1. Find any longest subsequence of consecutive empty stalls
  2. Choose the middle stalls

A great explanations by using tree n/2 & (n-1)/2

Coin Marketplace

STEEM 0.33
TRX 0.11
JST 0.034
BTC 66579.21
ETH 3282.19
USDT 1.00
SBD 4.30