一般情况下:
重载小于号,排序
struct Rnage{
int l,r;
bool operator < (const Range &W) const{
return r<W.r;
}
}range[N];
直接写比较函数是裸r的值,如果r<W.r,那么就是从小到大排序,但优先队列的是相反的
sort默认是从小到大排序,而优先队列默认从大到小排序。
直接写的比较函数:
bool cmp(int a,int b)//从大到小
{
return a>b;
}
sort(a+1,a+n+1,cmp);
struct Rnage{
int l,r;
bool operator < (const Range &W) const{
return r<W.r;
}
}range[N];
这个不是c++吧
重载小于号的
c++的STL吧
哦~~