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

#include"stdio.h"
int main()
{
	long n,a,b,x,y,s;
 	scanf("%ld",&n);
 	while(n--)
 	{
	 	scanf("%ld%ld",&a,&b);
	  	x=(a+b)/2;
	  	y=(a-b)/2;
	  	s=a+b;
	  	if(s%2!=0)
			printf("impossible\n");//a+b若为奇数,则x讲不会是整数;   else if(x<0||y<0) printf("impossible\n");
	  	else
		  	printf("%ld %ld\n",x,y);
    }
	return 0;
}

  

时间: 2024-10-30 14:28:22

Hdu 1194 Beat the Spread!的相关文章

(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 f

杭电 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)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&

POJ 2301 Beat the Spread!

超水的一题,输入(x+y)和(x-y)  输出x,y,但是注意输出x,y都为非负整数(因为这个我还wa了两次..唉~~) Beat the Spread! Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18154   Accepted: 8676 Description Superbowl Sunday is nearly here. In order to pass the time waiting for the h

Beat the Spread!

Beat the Spread! 垮掉的传播 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5329    Accepted Submission(s): 2782 Problem Description Superbowl Sunday is nearly here. In order to pass the time waitin

杭电ACM1194——Beat the Spread!

简单的数学题目,就是解方程. 不过需要注意的是,解出来的两个解没有负数. 输入m和n,方程1:x + y = m:方程2:| x - y | = n; x = (n + m)/ 2: y = (-n + m)/ 2: 注意:n + m和m - n 必须是偶数!~~做个判断就OK了. AC的代码: #include <iostream> using namespace std; int main() { int t, a, b; cin >> t; while(t--) { cin

hdu 2614 beat

这题最难得地方在于把题目看懂,简单的dfs,没什么好说的 #include<iostream> #include<cstring> #define maxn 15+1 using namespace std; int maxx; int mapp[maxn][maxn]; int visit[maxn]; int n; void dfs(int x,int time,int num) { for(int i=1;i<=n;i++) { if(!visit[i]&&am

HDU 2614 Beat(DFS)

题目链接 Problem Description Zty is a man that always full of enthusiasm. He wants to solve every kind of difficulty ACM problem in the world. And he has a habit that he does not like to solvea problem that is easy than problem he had solved. Now yifenfe