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

题目大意:已知一场比赛两个最终得分的和,以及两个最终得分的绝对值差。

求两个最终得分。若没有这样的两个得分,则输出impossible。最终得分不能

为负

思路:英语理解题。最主要的是读懂题意。两个最种得分的计算方法如下:

a = (s+d)/2,b = (s-d)/2。若a、b都为整数,且都大于0,则满足条件,

否则输出impossible

#include<stdio.h>

int main()
{
    int T,s,d;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&s,&d);
        int a = -1;
        int b = -1;
        if((s+d)%2 == 0)
        {
            a = (s+d)/2;
            b = (s-d)/2;
        }
        if(a>0 && b>0)
            printf("%d %d\n",a,b);
        else
            printf("impossible\n");
    }

    return 0;
}
时间: 2025-01-14 05:49:46

HDU1194_Beat the Spread!的相关文章

spread表格树实现

先上图看下效果图: 玩表格的朋友应该对Component和C1Flexgrid并不陌生吧.其实我也有用C1和DGV扩展了一个表格树,占有内存小,效率也可以,但是UI是硬伤,中规中矩,不美观.我上面是基于spread扩展实现的,站在可扩展的角度,C1不错,spread我可以说完全没有扩展性可言么?小日本写的代码感觉很不规范(反编译看的). 实现思路: 首列是重写BaseCellType基类,重绘了UI,主要是线.自定义图标.节点层级的绘制,主要是用rang确定绘制坐标,整个树层级的维护是基于链表实

[Redux] Avoiding Array Mutations with concat(), slice(), and ...spread

For Redux, you cannot use mutable methods like push, splice. Need to use immutable methods such as concat, slice and ...spread Html: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JS Bin</title> &

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

[ES6] 13. Using the ES6 spread operator ...

The spread operator (...) allows you to "explode" an array into its individual elements. Spreate an array: console.log([1,2,3]); // [1, 2, 3] console.log(...[1,2,3]); // 1 2 3 Spread out the second array and push that in first array: let first =

Spread JS 随笔一 简单表格

Spread JS 是一个在线Excel表格控件,功能非常强大.下面大概的介绍一下简单的使用. 最简单的表格 步骤 在工程文件中的head 部分引用相关的css 和js 1 <head> 2 <link rel="styleSheet" href="CSS/gc.spread.views.dataview.10.1.1.css" /> 3 <script src="JS/gc.spread.common.10.1.1.min.

[ES6] 23. Rest Parameters &amp; Spread Parameters

Rest Parameters: In ES5, when you don't know how many paramters will be passed in, you can use arguments: let sum = function(){ let result = 0; for(let i = 0; i < arguments.length; i++){ result += arguments[i]; } return result; } let result = sum(1,2

(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

ES6 spread operator 实现Function.prototype.apply

之前出于好奇想自己实现apply的功能(不使用call,bind),一写才发现用eval无法实现,除非传入的参数全是字符串. 今天突然看到这个ES6新特性spread opertor,发现有戏了 Function.prototype.apply2 = function(obj, arg) { var t = typeof obj == 'object' && !!obj ? obj : window, res; t.__func__ = this; if(arg) { if(!Array.

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