Mid calculated as low+((high-low+1)/2)

Правка en3, от arnav2004, 2021-02-18 11:26:59

I was recently solving this question using binary search.(https://mirror.codeforces.com/problemset/problem/1201/C)). I came to know about my mistake as my formula for calculating mid was low+(high-low)/2 but instead when I use low+(high-low+1)/2 I get AC.

My questions is how do all of you know which formula to use for calculating mid. I tried to google it and could not find any link which answers my question

Теги #binary search

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en6 Английский arnav2004 2021-02-18 11:56:04 9 Tiny change: 'ns is when do we use' -> 'ns is when(and why) do we use'
en5 Английский arnav2004 2021-02-18 11:35:49 66 Tiny change: 'earch(https://codefor' -> 'earch(http://codefor' (published)
en4 Английский arnav2004 2021-02-18 11:33:02 3
en3 Английский arnav2004 2021-02-18 11:26:59 2
en2 Английский arnav2004 2021-02-18 11:26:41 3
en1 Английский arnav2004 2021-02-18 11:25:54 444 Initial revision (saved to drafts)