UVa10812

題目:
https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=20&page=show_problem&problem=1753

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
int n;
cin >> n;
while(n--){
int s, d;
cin >> s >> d;
if(s < d || (s+d)%2 != 0 || (s-d)%2 != 0){
cout << "impossible\n";
continue;
}
int a = (s + d) / 2;
int b = (s - d) / 2;
if(a < 0 || b < 0){
cout << "impossible\n";
continue;
}
if(a < b) swap(a, b);
cout << a << ' ' << b << '\n';
}
return 0;
}