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;

import 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);
}
}
}
}

最新文章

  1. HDU 4122 Alice&#39;s mooncake shop --RMQ
  2. java中服务器启动时,执行定时任务
  3. Objective-C 编程艺术 (Zen and the Art of the Objective-C Craftsmanship 中文翻译)
  4. Servlet/jsp 中 获取页面所有传递参数
  5. C#配合利用XML文件构建反射表机制
  6. ReactNative实现图集功能
  7. JavaScript八张思维导图—Date用法
  8. Spring常用注解总结(2)
  9. python查看对象用法
  10. [Oralce][InMemory]如何确定一个表已经被Populate 到In Memory 中?
  11. SpringMVC使用Hession发布远程服务
  12. Pudding Monsters CodeForces - 526F (分治, 双指针)
  13. C#:匿名类型
  14. 廖雪峰Java5集合-3Map-1使用Map
  15. Linux未安装上传下载的插件,怎么进行文件的上传下载
  16. Nginx缓存使用官方教程及常见问题解答
  17. String类使用
  18. FreeRTOS软件定时器的使用
  19. ajax获取django的csrf_token
  20. Java50道经典习题-程序41 猴子分桃

热门文章

  1. 与Scheme共舞
  2. OpenStack对象存储——Swift
  3. excel导入mssql数据库,支持excel2003--2010文件格式
  4. 腾讯云升级到PHP7
  5. 《Java编程思想》之重点笔记——多态性理解
  6. PL/SQL客户端安装配置说明
  7. Android开发手记(12) Menu的使用
  8. 安全管理:IE6安全隐患重重 为何不离不弃
  9. PHP Sessions
  10. DirectX Graphics Infrastructure (DXGI) 全屏设置相关问题