HDOJ 1194 Beat the Spread!(简单题)

简介: HDOJ 1194 Beat the Spread!(简单题)

Problem 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?


Input

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


题意:输入2个数 a,b。

a是x,y的和,b是x,y的差。(x,y只能为正整数或者0)

如果x,y中出现了负数就输出impossible。

要注意的是x=(a+b)/2;y=(a-b)/2;

因为x,y是正整数,所以(a+b)%2==0且(a-b)%2==0;

Problem 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?
Input 
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
题意:输入2个数 a,b。 
a是x,y的和,b是x,y的差。(x,y只能为正整数或者0) 
如果x,y中出现了负数就输出impossible。 
要注意的是x=(a+b)/2;y=(a-b)/2; 
因为x,y是正整数,所以(a+b)%2==0且(a-b)%2==0;
————————————————
版权声明:本文为CSDN博主「谙忆」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_26525215/article/details/51049635import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int x=(a+b)/2;
            int y=(a-b)/2;
            if(x<0||y<0||(a+b)%2!=0||(a-b)%2!=0){
                System.out.println("impossible");
            }else{
                System.out.println(x+" "+y);
            }
        }
    }
}
目录
相关文章
hdoj 4706 Children's Day
题目意思就是用a-z组成一个N,然后到z后又跳回a,输出宽从3到10的N。
56 0
HDOJ 1326 Box of Bricks(简单题)
HDOJ 1326 Box of Bricks(简单题)
120 0
HDOJ 1326 Box of Bricks(简单题)
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ(HDU) 2088 Box of Bricks(平均值)
96 0
HDOJ(HDU) 2088 Box of Bricks(平均值)
HDOJ 2131 Probability
HDOJ 2131 Probability
102 0
|
Java
HDOJ1518Square 深搜
HDOJ1518Square 深搜
111 0
HDOJ(HDU) 2162 Add ‘em(求和)
HDOJ(HDU) 2162 Add ‘em(求和)
79 0
|
机器学习/深度学习
HDOJ 1334 Perfect Cubes(暴力)
HDOJ 1334 Perfect Cubes(暴力)
110 0
HDOJ 1008 Elevator
HDOJ 1008 Elevator
98 0
HDOJ 1014 Uniform Generator(公约数问题)
HDOJ 1014 Uniform Generator(公约数问题)
102 0
HDOJ1002题A + B Problem II,2个大数相加
HDOJ1002题A + B Problem II,2个大数相加
125 0

热门文章

最新文章

下一篇
开通oss服务