算法原理和ACM入门-NEFU-东北林业大学.PPT

算法原理和ACM入门-NEFU-东北林业大学

二分查找 二分函数直接用---不用自己写了 upper_bound()与lower_bound()使用方法 都是二分函数,头文件algorithm upper_bound返回第一个大于的元素的下标; lower_bound返回第一个大于等于元素的下标; #include iostream #include algorithm//必须包含的头文件 using namespace std; int main(){ ?int point[10] = {1,3,7,7,9}; ?int tmp = upper_bound(point, point + 5, 7) - point;//按从小到大,7最多能插入数组point的哪个位置 ?printf(%d\n,tmp); ?tmp = lower_bound(point, point + 5, 7) - point;////按从小到大,7最少能插入数组point的哪个位置 ?printf(%d\n,tmp); ?return 0; } output: 4 2 看代码---超短 #include iostream #include algorithm #include stdio.h using namespace std; int data[1000008]; int main() { int n,m

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档