(第一次写博客好紧张QAQ)
首先是模板·····两天前的时候写二分的时候一直都是胡搞····然后过题看运气?== 并不知道精度是什么样子的,直到昨天写的一个题的时候才仔究了一下整数二分的姿势(虽然那题其实并不是二分QWQ)(然后这个姿势应该没有问题?)
1 while ( left <= right ){ 2 int mid = left + ( right- left ) >> 1; 3 if ( judge(mid) < ans ) 4 left = mid + 1; 5 else 6 right = mid - 1; 7 } 8 //right 是 >= 中最小的 9 while ( left <= right ){ 10 int mid = left + ( right- left ) >> 1; 11 if ( judge(mid) <= ans ) 12 left = mid + 1; 13 else 14 right = mid - 1; 15 } 16 //left 是 <= 中最大的
感觉codeforces的b题或者c题有时候二分胡搞一下就能搞出来
下面是自己写过的一些二分查找题QWQQQ
待更新