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

当地的黑客组织打赌游戏。人们不是押了两个决赛分数的和(求s+d),

or on the absolute difference between the two scores.

就是押了两数之差的绝对值(求| s-d |)。

Given the winning numbers for each type of bet, can you deduce the final scores?

对于每一个赌注给一个赢得号码,你能推断出决赛分数吗?(用s和d求出决赛分数)

Input

The first line of input contains n, the number of test cases. n lines follow, each representing a test case.

输入的第一行是n,表示测试的个数。接下来是n行,每一行代表一个测试事件。

Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final scores.

对于每一个测试用例,给s和d。和是非负整数,差的绝对值。

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.

在单独的一行输出"impossible。(回想一下)记住,足球成绩总是非负整数  {(s+d)/2是整数}。

Sample Input

2
40 20   s   d
20 40

Sample Output

30 10     非负整数( s>d ),**不能是小数,也不能是负数,只能是0和正整数

目的:提取公因式,让公因式做判断语句,使代码看起来有很高的水平

因为答案不能为负数和小数,所以我们要排除这些答案

正真输出的只有0和正整数***

(s+d)/2     -----    (s-d)/2 

( s+d  + (s-d) -  (s-d) )/2 -------    (s-d)/2

d + (s-d)/2  ------    (s-d)/2   

目的完成:  公因式 (s-d)/2   ------ 

{ 改进:(s-d)&0x01  让 (s-d)与16进制1进行 异或 } 例:0011 0001 & 0000 0001 = 0000 0001

如果异或等于1 代表(s-d)是奇数,那么结果就是小数

impossible   s-d<0

Source

University of Waterloo Local Contest 2005.02.05

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		while (n-- > 0) {
			int s = sc.nextInt();
			int d = sc.nextInt();
			int temp = s - d;
			if (temp < 0 || (temp & 0x01) == 1) {
				System.out.println("impossible");
			} else {
				System.out.println((d + temp / 2) + " " + temp / 2);
			}
		}
	}

}
时间: 2024-10-12 03:24:55

Beat the Spread!的相关文章

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

(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

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

HDU1194_Beat the Spread!

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

北大ACM题库习题分类与简介(转载)

在百度文库上找到的,不知是哪位大牛整理的,真的很不错! zz题 目分类 Posted by fishhead at 2007-01-13 12:44:58.0 -------------------------------------------------------------------------------- acm.pku.edu.cn 1. 排序 1423, 1694, 1723, 1727, 1763, 1788, 1828, 1838, 1840, 2201, 2376, 23