261页binaryMaxIndexSmallerThanValue
来源:互联网 发布:python 参数 编辑:程序博客网 时间:2024/05/23 00:24
#include <iostream>#include <vector>using namespace std;template <typename Type>int binaryMaxIndexSmallerThanValue(const vector<Type> &array ,Type keyValue){if(array.size()==0)return -1;int left=0,right=array.size()-1;while(left<right-1){int midIndex=left+(right-left)/2;if(array[midIndex]<keyValue) left=midIndex;else //此等号位置非常重要right=midIndex;}if(array[right]<keyValue)return right;if(array[left]<keyValue)return left;return -1;}int main(){vector<int> sss;for(int i=1;i<100;++i){sss.push_back(49);}int index=binaryMaxIndexSmallerThanValue(sss,50);if(index>=0) cout<<index<<" "<<sss[index]<<endl;else cout<<"NULL"<<endl;system("pause");}
0 0
- 261页binaryMaxIndexSmallerThanValue
- 261
- Codeforces #261
- 261@365
- ocp-261
- SGU 261
- 261@365
- SGU 261
- 物料移动---261
- codeforces 261B
- codeforces round 261
- moncler coats-261
- sgu-261 Discrete Roots
- Codeforces 261B
- 点亮细胞261-270
- Codeforces Round #261 (Div. 2)
- Codeforces Round #261 (Div. 2)
- Codeforces Round #261 (Div. 2)
- 策略模式
- WAS7升级后遗症
- 将两个排好序的数组,合并到另外一个数组中,并且合并之后的数组也是有序的。
- Effective Java (7) 避免使用终结方法
- 图像分割—基于图的图像分割(OpenCV源码注解)
- 261页binaryMaxIndexSmallerThanValue
- 多重背包转换成完全背包和01背包
- HOJ 12822 The Alphabet Sticker
- bzoj1690 [Usaco2007 Dec]奶牛的旅行
- C语言,求数组中第二大值,两种方法.
- hdoj 1061 Rightmost Digit 【数论】
- NSInvocation在获取返回值后crash问题
- 【代码优化】方法签名及参数检查
- 如何快速启动Android模拟器(Android Emulator)