Last active
August 29, 2015 14:03
-
-
Save cocodrips/8c6ecfa61a2fb7be82fe to your computer and use it in GitHub Desktop.
C++つらい ICPC2013予選 A問題
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 <iostream> | |
#include <utility> | |
#include <algorithm> | |
#include <vector> | |
#include <math.h> | |
using namespace std; | |
const int N = 150; | |
int right(vector< pair<int, int> > areas, int area, int h){ | |
for (int i = 0; i < areas.size(); ++i){ | |
if(area == areas[i].first && h < (areas[i].second >> 10)){ | |
return areas[i].second; | |
} else if(area < areas[i].first){ | |
return areas[i].second; | |
} | |
} | |
return 0; | |
} | |
int main(int argc, char const *argv[]) | |
{ | |
vector< pair<int, int> > areas; | |
for (int i = 0; i < N; ++i){ | |
for (int j = 0; j < i; ++j){ | |
pair<int, int> p; | |
p.first = pow(i+1, 2) + pow(j+1, 2); | |
p.second = ((j + 1) << 10) + (i + 1); | |
areas.push_back(p); | |
} | |
} | |
sort(areas.begin(), areas.end()); | |
while(1){ | |
int h, w; | |
cin >> h >> w; | |
if(h == 0 && w == 0) break; | |
int t = pow(h, 2) + pow(w, 2); | |
int ans = right(areas, t, h); | |
cout << (ans >> 10) << " " << ans % (1 << 10) << endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment