标签:http 奶牛 复杂 ble targe while else color get
时间复杂度O(logn)
当函数具有单调性时
在范围内
二分答案的一边可以而另一边不可以
通过二分把范围逐渐缩小
1.当了l<=r时,边界缩为mid-1与mid+1
while(l<=r) //l=左边界,r=右边界 { int mid=(l+r)/2; if(check(mid))r=mid-1; else l=mid+1; }
2.当了l<=r时,边界缩为mid-1与mid+1
while(l<r) { int mid=(l+r)/2; if(check(mid))r=mid; else l=mid+1; }
不确定是mid,mid-1,mid+1哪一个时,建议最后暴力
标签:http 奶牛 复杂 ble targe while else color get
原文地址:https://www.cnblogs.com/QAQq/p/10300580.html