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

Revision en1, by arnav2004, 2021-02-18 11:25:54

I was recently solving this question using binary search.(https://codeforces.net/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

Tags #binary search

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English 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 English arnav2004 2021-02-18 11:35:49 66 Tiny change: 'earch(https://codefor' -> 'earch(http://codefor' (published)
en4 English arnav2004 2021-02-18 11:33:02 3
en3 English arnav2004 2021-02-18 11:26:59 2
en2 English arnav2004 2021-02-18 11:26:41 3
en1 English arnav2004 2021-02-18 11:25:54 444 Initial revision (saved to drafts)