fork(1) download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <utility>
  5. using namespace std;
  6.  
  7. typedef pair<int, int> P;
  8.  
  9. bool compare(P a, P b) {
  10. if(a.first*a.first+a.second*a.second == b.first*b.first+b.second*b.second) return a.first < b.first;
  11. return a.first*a.first+a.second*a.second < b.first*b.first+b.second*b.second;
  12. }
  13.  
  14.  
  15. int main() {
  16. vector<P> vec;
  17. for(int i = 1; i <= 150; i++) {
  18. for(int j = i + 1; j <= 150; j++) {
  19. vec.push_back(P(i,j));
  20. }
  21. }
  22. sort(vec.begin(), vec.end(), compare);
  23. for(int h, w; cin >> h >> w, h || w; ) {
  24. int t;
  25. for(int i = 0; i < (int)vec.size(); i++) {
  26. if(P(h,w) == vec[i]) {
  27. t = i;
  28. break;
  29. }
  30. }
  31. cout << vec[t+1].first << ' ' << vec[t+1].second << endl;
  32. }
  33. }
  34.  
Success #stdin #stdout 0s 3036KB
stdin
1 2
1 3
2 3
1 4
2 4
5 6
1 8
4 7
98 100
99 100
0 0
stdout
1 3
2 3
1 4
2 4
3 4
1 8
4 7
2 8
3 140
89 109