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

Waterloo local 2005.02.05

 1 //oimonster
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<iostream>
 5 using namespace std;
 6 int main(){
 7     int i,j,n,a,b,c,d;
 8     scanf("%d",&n);
 9     for(i=1;i<=n;i++){
10         scanf("%d%d",&a,&b);
11         c=(a+b)/2;
12         d=(a-b)/2;
13         if((c<0)||(d<0)||((a+b)%2!=0))printf("impossible\n");
14         else printf("%d %d\n",c,d);
15     }
16     return 0;
17 }

时间: 2024-10-10 00:26:08

POJ 2301 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): 7001    Accepted Submission(s): 3700 Problem Description Superbowl Sunday is nearly here. In order to pass the time waiting for t

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

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

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

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百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

ACM训练方案-POJ题目分类

ACM训练方案-POJ题目分类 博客分类: 算法 ACM online Judge 中国: 浙江大学(ZJU):http://acm.zju.edu.cn/ 北京大学(PKU):http://acm.pku.edu.cn/JudgeOnline/ 杭州电子科技大学(HDU):http://acm.hdu.edu.cn/ 中国科技大学(USTC):http://acm.ustc.edu.cn/ 北京航天航空大学(BUAA)http://acm.buaa.edu.cn/oj/index.php 南京