Skip to content

Instantly share code, notes, and snippets.

@Shirataki2
Created May 4, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shirataki2/e91e56961f76289ea76d5c8d21fc9bc0 to your computer and use it in GitHub Desktop.
Save Shirataki2/e91e56961f76289ea76d5c8d21fc9bc0 to your computer and use it in GitHub Desktop.
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 1; i < n; i++)
using namespace std;
static const int MAX = 151;
class Rect {
public:
int h, w;
Rect(int _h, int _w) {
h = _h;
w = _w;
}
int length() { return h * h + w * w; }
bool operator<(Rect r) {
return make_pair(length(), h) < make_pair(r.length(), r.h);
}
};
int main() {
vector<Rect> r;
int h, w;
REP(x, MAX) {
REP(y, x) { r.push_back(Rect(y, x)); }
}
sort(r.begin(), r.end());
while (cin >> h >> w, h) {
for (int i = 0; i < r.size(); i++) {
if (r[i].h == h && r[i].w == w)
cout << r[i + 1].h << " " << r[i + 1].w << endl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment