Coding Practice Diary - Recursive C_stalls

in coding •  7 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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!