#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct compareFirstPairMember {
bool operator()(const pair<int, int>& a, const pair<int, int>& b) const {
return a.first > b.first;
}
};
int main() {
vector<pair<int, int>> v;
vector<pair<int, int>> p;
v.push_back(pair<int,int>(1,2));
v.push_back(pair<int,int>(1,3));
v.push_back(pair<int,int>(2,1));
v.push_back(pair<int,int>(1,2));
do {
for(auto item : v)
cout << item.first << " " << item.second << endl;
cout << endl;
} while ( std::next_permutation(begin(v), end(v), compareFirstPairMember()));
v.resize(unique(v.begin(),v.end())-v.begin(), compareFirstPairMember());
for(int i=0;i<v.size();i++)
cout<<v[i].first<<" "<<v[i].second<<endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnN0cnVjdCBjb21wYXJlRmlyc3RQYWlyTWVtYmVyIHsKICAgIGJvb2wgb3BlcmF0b3IoKShjb25zdCBwYWlyPGludCwgaW50PiYgYSwgY29uc3QgcGFpcjxpbnQsIGludD4mIGIpIGNvbnN0IHsKICAgICAgICByZXR1cm4gYS5maXJzdCA+IGIuZmlyc3Q7CiAgICB9Cn07CgppbnQgbWFpbigpIHsKCQoJdmVjdG9yPHBhaXI8aW50LCBpbnQ+PiB2OwoJCXZlY3RvcjxwYWlyPGludCwgaW50Pj4gcDsKCXYucHVzaF9iYWNrKHBhaXI8aW50LGludD4oMSwyKSk7CiAgICB2LnB1c2hfYmFjayhwYWlyPGludCxpbnQ+KDEsMykpOwogICAgdi5wdXNoX2JhY2socGFpcjxpbnQsaW50PigyLDEpKTsKICAgIHYucHVzaF9iYWNrKHBhaXI8aW50LGludD4oMSwyKSk7CgkKCQoJCglkbyB7CgkJZm9yKGF1dG8gaXRlbSA6IHYpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGNvdXQgPDwgaXRlbS5maXJzdCA8PCAiICIgPDwgaXRlbS5zZWNvbmQgPDwgZW5kbDsKICAgICAgICBjb3V0IDw8IGVuZGw7CiAgICB9IHdoaWxlICggc3RkOjpuZXh0X3Blcm11dGF0aW9uKGJlZ2luKHYpLCBlbmQodiksIGNvbXBhcmVGaXJzdFBhaXJNZW1iZXIoKSkpOwoJdi5yZXNpemUodW5pcXVlKHYuYmVnaW4oKSx2LmVuZCgpKS12LmJlZ2luKCksIGNvbXBhcmVGaXJzdFBhaXJNZW1iZXIoKSk7Cglmb3IoaW50IGk9MDtpPHYuc2l6ZSgpO2krKykKCSAgY291dDw8dltpXS5maXJzdDw8IiAiPDx2W2ldLnNlY29uZDw8ZW5kbDsKCXJldHVybiAwOwp9
prog.cpp: In function ‘int main()’:
prog.cpp:29:72: error: no matching function for call to ‘std::vector<std::pair<int, int> >::resize(__gnu_cxx::__normal_iterator<std::pair<int, int>*, std::vector<std::pair<int, int> > >::difference_type, compareFirstPairMember)’
v.resize(unique(v.begin(),v.end())-v.begin(), compareFirstPairMember());
^
In file included from /usr/include/c++/6/vector:64:0,
from prog.cpp:2:
/usr/include/c++/6/bits/stl_vector.h:674:7: note: candidate: void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]
resize(size_type __new_size)
^~~~~~
/usr/include/c++/6/bits/stl_vector.h:674:7: note: candidate expects 1 argument, 2 provided
/usr/include/c++/6/bits/stl_vector.h:694:7: note: candidate: void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::pair<int, int>; _Alloc = std::allocator<std::pair<int, int> >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::pair<int, int>]
resize(size_type __new_size, const value_type& __x)
^~~~~~
/usr/include/c++/6/bits/stl_vector.h:694:7: note: no known conversion for argument 2 from ‘compareFirstPairMember’ to ‘const value_type& {aka const std::pair<int, int>&}’