As you state to avoid infinite loop in BsFirst you must to add one int mid = (lo+up+1)/2 but this if lo == up what if they are not equal won't it affect the answer?????
Also, in most solutions and on top coder i found the solution like this binary_search(lo, hi, p): while lo < hi: mid = lo + (hi-lo)/2 if p(mid) > target: hi = mid else: lo = mid+1 which mean hi = mid not mid-1 rescource : www.topcoder.com/community/data-science/data-science-tutorials/binary-search/
I think I said you have to try the different formulas to select one that doesn't go infinite there are 3 different cases and each one needs different formula if i remember
كان عندي سؤال لو سمحت يا دكتور حاليا أنا ماشي ف الشيت لكن مسائل الUVA الموقع مش راضي يفتح عندي ف هل أدخل فيديو الحل أقرأ المسألة وأفكر في طريقة الحل وبعدين أسمعه ومكتبش كود لإن كدا كدا مش هعرف أختبره ولا أكتبه برضو ??
شرح عظييييييييييييييييييم جدا وواضح ياريت كل شي مثله :)
جامد جدا، محتوى مقالة توب كودر مشروح عربي ❤❤
جامد بجد❣❣
As you state to avoid infinite loop in BsFirst you must to add one int mid = (lo+up+1)/2
but this if lo == up what if they are not equal won't it affect the answer?????
Also, in most solutions and on top coder i found the solution like this
binary_search(lo, hi, p):
while lo < hi:
mid = lo + (hi-lo)/2
if p(mid) > target:
hi = mid
else:
lo = mid+1
which mean hi = mid not mid-1
rescource :
www.topcoder.com/community/data-science/data-science-tutorials/binary-search/
one can write things in different ways. Find an example that break my codes and notify me
I think I said you have to try the different formulas to select one that doesn't go infinite
there are 3 different cases and each one needs different formula if i remember
جزاك الله خيرا
رائع اخى
كان عندي سؤال لو سمحت يا دكتور
حاليا أنا ماشي ف الشيت لكن مسائل الUVA الموقع مش راضي يفتح عندي ف هل أدخل فيديو الحل أقرأ المسألة وأفكر في طريقة الحل وبعدين أسمعه ومكتبش كود لإن كدا كدا مش هعرف أختبره ولا أكتبه برضو ??
Did u remove cookies? Google internet for this problem
@@ArabicCompetitiveProgramming
The problem has been solved..
جزاك الله خيرا
Notes are different and more practical !!!.
وعليكم السلام ورحمة الله وبركاته
جزاك الله خيرا