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


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

}
















  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值