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

HDOJ 1194 Beat the Spread!(简单题)的更多相关文章

  1. HDOJ 1326 Box of Bricks(简单题)

    Problem Description Little Bob likes playing with his box of bricks. He puts the bricks one upon ano ...

  2. HDU 1194 - Beat the Spread!

    给两数之和和两数之差,求两数,两数还必须同奇偶 #include <iostream> using namespace std; int main() { int a,b,t; cin&g ...

  3. DFS HDOJ 2614 Beat

    题目传送门 /* 题意:处理完i问题后去处理j问题,要满足a[i][j] <= a[j][k],问最多能有多少问题可以解决 DFS简单题:以每次处理的问题作为过程(即行数),最多能解决n个问题, ...

  4. BZOJ 2683: 简单题

    2683: 简单题 Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 913  Solved: 379[Submit][Status][Discuss] ...

  5. 【BZOJ-1176&2683】Mokia&简单题 CDQ分治

    1176: [Balkan2007]Mokia Time Limit: 30 Sec  Memory Limit: 162 MBSubmit: 1854  Solved: 821[Submit][St ...

  6. Bzoj4066 简单题

    Time Limit: 50 Sec  Memory Limit: 20 MBSubmit: 2185  Solved: 581 Description 你有一个N*N的棋盘,每个格子内有一个整数,初 ...

  7. Bzoj2683 简单题

    Time Limit: 50 Sec  Memory Limit: 128 MBSubmit: 1071  Solved: 428 Description 你有一个N*N的棋盘,每个格子内有一个整数, ...

  8. 这样leetcode简单题都更完了

    这样leetcode简单题都更完了,作为水题王的我开始要更新leetcode中等题和难题了,有些挖了很久的坑也将在在这个阶段一一揭晓,接下来的算法性更强,我就要开始分专题更新题目,而不是再以我的A题顺 ...

  9. [BZOJ2683][BZOJ4066]简单题

    [BZOJ2683][BZOJ4066]简单题 试题描述 你有一个N*N的棋盘,每个格子内有一个整数,初始时的时候全部为0,现在需要维护两种操作: 命令 参数限制 内容 1 x y A 1<=x ...

随机推荐

  1. 什么是IP地址、子网掩码、路由和网关

    什么是IP地址.子网掩码.路由和网关?经常有朋友问我,的确这些术语常常被我们看到,今天就给大伙说说这几个术语的意思: 1.IP地址: IP地址有一个32位的连接地址,由4个8位字段组成,8位字段称为8 ...

  2. Android BaseAdapter Gallery 画廊视图 (左右拖动图片列表拖至中间时图片放大显示)

    画廊视图使用Gallery表示,能够按水平方向显示内容,并且可以手指直接拖动图片和移动,一般用来浏览图片,,被选中的选项位于中间,并且可以响应事件显示信息.在使用画廊视图时,首先在屏幕上添加Galle ...

  3. 生成唯一的id(转)

    很多朋友都利用md5()来生成唯一的编号,但是md5()有几个缺点:1.无序,导致数据库中排序性能下降.2.太长,需要更多的存储空间.其实PHP中自带一个函数来生成唯一的id,这个函数就是uniqid ...

  4. MM32/STM32中断和事件梳理

    Interrupt_event梳理 预备资料 MM32/stm32中文参考手册 Cortex-M3权威指南(深入了解中断和异常) MM32F103产品手册(配置GPIO的复用功能可能用到) 提出问题 ...

  5. Everything 使用技巧

    使用技巧 可以使用逻辑符空格(与), |(或),!(非),及通配符 * 和 ? ,符号或搜索内容之间必须加空格且空格任意使用如果经常搜索同一内容,可以使用书签功能,且可以对书签进行添加.编辑.排序.导 ...

  6. css10定位属性

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  7. cogs 线型网络(状压dp)

    /* 需要好大的空间..... 而且lowbit理解的不是很好 先放到博客里 以后慢慢研究 */ #include<iostream> #include<cstdio> #in ...

  8. Session深度探索

    什么是Session? web是无状态,这意味着每次页面被回传到服务器时,都重新生成一个web页面类的一个新的实例.众所周知http时无状态的协议.它不能获得客户端的信息.如果用户录入了一些信息,当跳 ...

  9. Linq使用GroupBy筛选数据

    StringBuilder sb = new StringBuilder(); List<IGrouping<string, modle>> listRepeat = mode ...

  10. 查询oracle表和sql数据量大小

    select t.TABLE_NAME,t.NUM_ROWS from user_tables t order by t.TABLE_NAME:--oracle  SELECT object_name ...