When we use the set set, when the set set is made up of two simple variables, we can define our own struct and define the overloaded less-than sign, as shown below:
- struct ju
- {
- int x,y;
- bool operator < ( const ju &a) const //sort and repeat
- {
- if (a.x! = x)
- & nbsp return a.x >x;
- return a.y > y;
- &NBSP;&NBSP;&NBSP;&NBSP;}&NBSP;&NBSP;
- }tt;
However, it is necessary to define the structure itself, sometimes we need to define the constructor in the structure, if only two variables, we can be implemented by the pair type, it is concise.
struct Ratiocomp {
bool operator() (const pair<int, int>& A, const pair<int, int>& B) {
if (A.First * b.second < A.second * b.first) {
return true;
} Else if (A.First * B.second = = = A.second * b. First) {
return A.First < B.first;
} Else {
return false;
}
}
};
Set<pair<int,int;,ratiocomp>S;
A constructor defined in a ratiocomp struct is a set set collation.
Combined use of C + + set and pair