(hdu 简单题 128道)hdu 1194 Beat the Spread!(已知两个数的和u两个数的差求这两个数)

题目:

Beat the Spread!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5169    Accepted Submission(s): 2692

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

Source

University of Waterloo Local Contest 2005.02.05

Recommend

Ignatius.L   |   We have carefully selected several similar problems for you:  1163 1201 1164 1205 1152

题目分析:

已知a+b和a-b求a、b。

代码如下:

/*
 * b.cpp
 *
 *  Created on: 2015年3月12日
 *      Author: Administrator
 */

#include <iostream>
#include <cstdio>

using namespace std;

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int sum;
		int diff;
		scanf("%d%d",&sum,&diff);

		if(sum < diff){//如果两个数的和<两个数的差
			printf("impossible\n");//不可能有结果(a,b均>=0)
		}else if((sum+diff)%2 != 0){//如果(a+b) + (a-b) 不是偶数
			printf("impossible\n");//不可能
		}else{//否则符合正常逻辑
			printf("%d %d\n",(sum+diff)/2,(sum-diff)/2);//计算这两个数都是什么
		}
	}

	return 0;
}
时间: 2024-10-21 22:20:43

(hdu 简单题 128道)hdu 1194 Beat the Spread!(已知两个数的和u两个数的差求这两个数)的相关文章

(hdu 简单题 128道)AC Me(统计一行文本中各个字母出现的次数)

题目: AC Me Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13465    Accepted Submission(s): 5927 Problem Description Ignatius is doing his homework now. The teacher gives him some articles and as

(hdu 简单题 128道)平方和与立方和(求一个区间的立方和和平方和)

题目: 平方和与立方和 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 108212    Accepted Submission(s): 34915 Problem Description 给定一段连续的整数,求出他们中所有偶数的平方和以及所有奇数的立方和. Input 输入数据包含多组测试实例,每组测试实例包含一行,由两个整数m和n组

(hdu 简单题 128道)Lowest Bit(求一个数的二进制的最后一个非零位对应的十进制数)

题目: Lowest Bit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8722    Accepted Submission(s): 6428 Problem Description Given an positive integer A (1 <= A <= 100), output the lowest bit of A.

(hdu 简单题 128题)hdu 2005 第几天(计算当天是该年的第几天)

题目: 第几天? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 89641    Accepted Submission(s): 33727 Problem Description 给定一个日期,输出这个日期是该年的第几天. Input 输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,

Hdu 1194 Beat the Spread!

Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7001    Accepted Submission(s): 3700 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for t

杭电 HDU 1194 Beat the Spread!

Beat the Spread! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5192    Accepted Submission(s): 2705 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for

(hdu step 5.1.4)Farm Irrigation(在两个节点合并有限制条件的情况下,求集合的个数)

题目: Farm Irrigation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 202 Accepted Submission(s): 104   Problem Description Benny has a spacious farm land to irrigate. The farm land is a rectangle,

(HDU)1194 -- Beat the Spread!(球场赌徒)

题目链接:http://vjudge.net/problem/HDU-1194 给你两个非负整数的和以及差的绝对值,求出这个两个数,不存在输出impossible 坑爹的地方,如果两个数的和是一个奇数,整数解不存在. #include <iostream> #include <cstdio> using namespace std; int main() { int t,a,b,he,ca; scanf("%d",&t); while(t--) { sc

HDOJ 1194 Beat the Spread!

[题意]:给出两个数 m n,第一个数是另外两个数a b的和,第二个数是a b的差的绝对值(absolute difference).输出这两个数a b,大的在前. [思路]:大的数等于 (m+n)/2,小的等于m-大的. [注意]:impossible的判断.分两种,一种是m<n,一种是m+n为奇数的情况.如果m+n为奇数,则a b不存在. [AC代码]: #include <iostream> #include <cstdlib> #include <cstdio&