<span>二分模版</span>
详情请见http://blog.csdn.net/int64ago/article/details/7425727
//二分查找(找到返回左端,找不到返回右端) int bSearch(int x,int y,int g) { int mid,l=x,r=y; while(l<=r) { mid=(l+r)>>1; if(a[mid]>=g) r=mid-1; else l=mid+1; } return l; } //二分查找(找到返回右端,找不到返回左端) int bSearch(int x,int y,int g) { int mid,l=x,r=y; while(l<=r) { mid=(l+r)>>1; if(a[mid]>g) r=mid-1; else l=mid+1; } return r; }