关于 lower_bound 的重载优先级用法
  • 板块学术版
  • 楼主dreampioneer
  • 当前回复9
  • 已保存回复9
  • 发布时间2022/4/28 17:07
  • 上次更新2023/10/28 02:44:04
查看原帖
关于 lower_bound 的重载优先级用法
651931
dreampioneer楼主2022/4/28 17:07

RT,bdfs的时候看到这个:

int pos3=lower_bound(num,num+6,7,greater<int>())-num; //返回数组中第一个小于等于查询数的值

但是调代码的时候出现了问题,我于是试了一下,用了以下代码:

#include <bits/stdc++.h>
using namespace std;
int a[100]={0,3,12,17,33,34};
int main() {
	printf("%d\n",lower_bound(a+1,a+1+5,13,greater<int>()-a);

输了个 66,也就是 a.end()

不信邪手打了个 cmp

#include <bits/stdc++.h>
using namespace std;
bool cmp (int a,int b){return a>b;}
int a[100]={0,3,12,17,33,34};
int main() {
   printf("%d\n",lower_bound(a+1,a+1+5,13,cmp)-a);
}

输的还是 66……

所以如何重载 lower_bound 的优先级,bdfs无果。

2022/4/28 17:07
加载中...