1.链接地址
https://vjudge.net/problem/POJ-2301
2.问题描述
Superbowl Sunday is nearly here. In order to pass the time waiting for the half-time commercials and wardrobe malfunctions, the local hackers have organized a betting pool on the game. Members place their bets on the sum of the two final scores, or on the absolute difference between the two scores.
Given the winning numbers for each type of bet, can you deduce the final scores?
输入样例
2 40 20 20 40
输出样例
30 10 impossible
3.解题思路
记得两个数相加或相减的奇偶性是一致的
4.算法实现源代码
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; int main() { int n; scanf("%d",&n); while(n--) { int sum,cha; scanf("%d %d",&sum,&cha); if(sum<cha) { printf("impossible\n"); } else if((sum%2==0&&cha%2==1)||(cha%2==0&&sum%2==1)) { cout<<"impossible"<<endl; } else { printf("%d %d\n",(sum+cha)/2,(sum-cha)/2); } } }