//二分求分界点
//整数二分找右分界点
//即目标点后面的所有点满足条件
//返回值为第一个满足目标点的元素
int bsearch_1(int l,int r)
{
while(l<r)
{
int mid = l+r>>1;
if(check(mid)) r=mid;//向左边找
else l =mid +1;
}
return l;
}
//整数二分找左端点
//即目标点前面的所有点满足条件
int bserch_2(int l,int r)
{
while(l<r)
{
int mid =l+r+1>>1; //加一向上取整
if(check(mid))l=mid;
else r =mid-1;
}
return l;
}
//浮点数二分求右边界
double bsearch_3(double l,double r)
{
while(r-l>精度)
{
double mid =(l+r)/2;
if(check(mid))r=mid;
else l = mid;
}
return l;
}
//浮点数求二分求左边界
double bserch_4(double l,double r)
{
while(r-l>精度)
{
double mid =l+r+1>>1; //加一向上取整
if(check(mid))l=mid;
else r =mid;
}
return l;
}