Skip to content

Instantly share code, notes, and snippets.

@oisincar
Created November 30, 2016 14:39
Show Gist options
  • Save oisincar/204bbaaef5a5744f9b02f96fd9d005ed to your computer and use it in GitHub Desktop.
Save oisincar/204bbaaef5a5744f9b02f96fd9d005ed to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
bool sortfunc(pair<int, int> p1, pair<int, int> p2){
return pow(p1.first, 2) + pow(p1.second, 2) <
pow(p2.first, 2) + pow(p2.second, 2);
}
int main(){
int n; cin >> n;
vector<pair<int, int>> int_p(n);
for (auto e : int_p){
cin >> e.first >> e.second;
}
// or use & for basic types.
int s; cin >> s;
vector<int> int_vec(s);
for(auto &e : int_vec){
cin >> e;
}
// also sorting is ez..
// range is exclusive of end point (i.e. [begin, end) in sort(begin, end) )
sort(int_vec.begin(), int_vec.end());
// or
sort(int_vec.begin(), int_vec.begin() + s);
// sort second half of list based on function (distance).
sort(int_p.begin()+(n/2), int_p.end(), sortfunc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment