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

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

Hello Codeforces. I've analyzed a lot of solutions of today's problem E (round 643) and at a lot of them i've seen ternary search. I understood why binary search can't work in this scenario, but can someone please give me some good explanation on when whe should use ternary search? Maybe some signs which instantly tells us that ternary search should be used?

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

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

Auto comment: topic has been updated by Brodicico (previous revision, new revision, compare).

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

When I see that U shape structure, Increases both side but optimal at some middle structure.. I almost assume its ternary search..

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

I never learned ternary search before but I solved today's E question with binary search (my submission: 80368801).

When I iterated over the final target height I noticed that the total cost was decreasing and then increasing, so I suppose that a function with this property can be minimized with ternary search.

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

As far as I know, it is used to find the only maxima/ minim of a concave/ convex graph traced out by an evaluation function on various inputs. here is a detailed solution of codeforces problem, trying to explain the ternary search in more deatail.

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

Binary search is for monotonic functions. Ternary search is for unimodal functions. It must be strict unimodal else the search will halt as soon as it finds a plateau (0 slope). Note every strictly monotonic function is a degenerate unimodal function (with no left or right tail) so ternary search will work when binary search does as long as the monotonicity is strict. Here is some code: https://codeforces.me/blog/entry/43440

Notice the logic for determining which side to recurse on is really a difference quotient, a discrete derivative, slope etc.