Problem Links:
poj2301,
Problem:
Beat the Spread!
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 13901 | Accepted: 6611 |
Description
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?
Given the winning numbers for each type of bet, can you deduce the final scores?
The
first line of input contains n, the number of test cases. n lines
follow, each representing a test case. Each test case gives s and d,
non-negative integers representing the sum and (absolute) difference
between the two final scores.
Output
For
each test case, output a line giving the two final scores, largest
first. If there are no such scores, output a line containing
"impossible". Recall that football scores are always non-negative
integers.
Sample Input
2 40 20 20 40
Sample Output
30 10 impossible
Source
Waterloo local 2005.02.05
Solution:
Straight forward. Just take care about that the two numbers should be both of even or odd at the same time.
Source Code:
//Mon Apr 19 01:34:56 CDT 2010#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char* argv[])
{
// freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
int N;
cin >> N;
for (int ncase = 0; ncase < N; ncase++)
{
int a, b;
cin >> a >> b;
if ((a + b) % 2 != 0 || a < b)
{
cout << "impossible" << endl;
continue;
}
cout << (a+b)/2 << " " << (a-b)/2 << endl;
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
No comments :
Post a Comment