Created
November 30, 2016 14:39
-
-
Save oisincar/204bbaaef5a5744f9b02f96fd9d005ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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