自定义lower_bound比较函数

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

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
//#include
#include
#define up(i,a,b)  for(int i=a;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;
	}
}

你可能感兴趣的:(stl)