24h購物| | PChome| 登入
2012-04-15 17:55:48| 人氣3,103| 回應0 | 上一篇 | 下一篇

[UVA] 10812 - Beat the Spread!

推薦 0 收藏 0 轉貼0 訂閱站台

Problem D: Beat the Spread!

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?

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. 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

Output for Sample Input

30 10
impossible


 
#include <stdio.h>

int main() {
    int n, s, d, a, b;
    scanf("%d", &n);
    while(n--) {
        scanf("%d %d", &s, &d);
        a = (s+d);
        b = (s-d);
        if(a < 0 || b < 0 || a%2 == 1 || b%2 == 1)
            puts("impossible");
        else
            printf("%d %d\n", a/2, b/2);
    }
    return 0;
}


台長: Morris
人氣(3,103) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[UVA] 156 - Ananagrams
此分類上一篇:[UVA] 11799 - Horror Dash

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文