标签:while find span 二分 font family div mic nbsp
int findl(int x) { int l = 1, r = n + 1; while(l < r) { int mid = l + r >> 1; if(a[mid].pos >= x) r = mid; else l = mid + 1; } //mid取不到r,而r一开始取n+1有利于查找正确答案 }
在序列中寻找小于等于x的最大值
int findr(int x) { int l = 0, r = n; while(l < r) { int mid = l + r + 1 >> 1; if(a[mid].pos<= x) l = mid; else r = mid - 1; } //原理同上 }
标签:while find span 二分 font family div mic nbsp
原文地址:https://www.cnblogs.com/smartljy/p/11781457.html