Skip to content

Instantly share code, notes, and snippets.

@cocodrips
Last active August 29, 2015 14:03
Show Gist options
  • Save cocodrips/bebfc1065ceec5aae73f to your computer and use it in GitHub Desktop.
Save cocodrips/bebfc1065ceec5aae73f to your computer and use it in GitHub Desktop.
ICPC2013予選、A問題をもうちょっとちゃんと解く
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <tuple>
#include <math.h>
using namespace std;
const int N = 150;
int main(int argc, char const *argv[]){
vector<tuple<int, int, int> > rects;
for (int w = 0; w < N; ++w){
for (int h = 0; h < w; ++h){
int d = pow(w+1, 2) + pow(h+1, 2);
rects.push_back(make_tuple(d, h + 1, w + 1));
}
}
sort(rects.begin(), rects.end());
while(1){
int h, w;
cin >> h >> w;
if(h == 0 && w == 0) break;
int t = pow(h, 2) + pow(w, 2);
auto up = upper_bound(rects.begin(), rects.end(), make_tuple(t, h, w));
cout << get<1>(*up) << " " << get<2>(*up) << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment