自定义lower_bound比较函数

重载比较符号或者自定义比较函数均可。
记得比较的时候需要放结构体进去比较。
如用vetor存结构体比较或者直接结构体比较。

#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<map>
//#include<regex>
#include<cstdio>
#define up(i,a,b)  for(int i=a;i<b;i++)
#define dw(i,a,b)  for(int i=a;i>b;i--)
#define upd(i,a,b) for(int i=a;i<=b;i++)
#define dwd(i,a,b) for(int i=a;i>=b;i--)
//#define local
typedef long long ll;
const double esp = 1e-6;
const double pi = acos(-1.0);
const int INF = 0x3f3f3f3f;
const int inf = 1e9;
using namespace std;
int read()
{
	char ch = getchar(); int x = 0, f = 1;
	while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
typedef pair<int, int> pir;
struct node { int b,c; 
node(int b=0,int c=0):b(b) ,c(c) {}
bool operator<(const node &a)const
{
	return b == a.b ? c < a.c : b < a.b;
}
};//重载<符号
bool cmp(node a, node b)
{
	return a.b == b.b ? a.c < b.c : a.b < b.b;
}//纯粹的比较函数
int main()
{
	node a[100];
	upd(i, 1, 10)
	{
		a[i] = node(i, 10);
	}
	upd(i, 1, 10)
	{
		cout << "i" << i << " ";
		cout<<lower_bound(a+1,a+11,node(1,10))-a-1<<endl;
		cout << upper_bound(a + 1, a + 11,node(i,10),cmp) - a - 1 << endl;
	}
}
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值