第一个大于 x 的数
2026-03-28 15:19:14
发布于:江苏
0阅读
0回复
0点赞
用 upper_bound。
upper_bound(begin,end,x) 返回区间 [begin,end) 内第一个严格大于 x 的数的地址,如果没找到就返回 end。
所以,用 upper_bound 的结果减掉数组首元素地址就是答案了。
代码
cout << upper_bound(a+1,a+n+1,x)-a;
就这么简单
这里空空如也
2026-03-28 15:19:14
发布于:江苏
用 upper_bound。
upper_bound(begin,end,x) 返回区间 [begin,end) 内第一个严格大于 x 的数的地址,如果没找到就返回 end。
所以,用 upper_bound 的结果减掉数组首元素地址就是答案了。
cout << upper_bound(a+1,a+n+1,x)-a;
就这么简单
这里空空如也
提交答案之后,这里将显示提交结果~
有帮助,赞一个