您的位置:首页 > 其它

HDU1194 POJ2301 UVA10812 ZOJ2388 Beat the Spread!【数学】

2017-12-09 07:24 555 查看

Beat the Spread!

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7508    Accepted Submission(s): 3961


[align=left]Problem Description[/align]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?
 
[align=left]Input[/align]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.
 
[align=left]Output[/align]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.
 
[align=left]Sample Input[/align]
2
40 20
20 40 
[align=left]Sample Output[/align]
30 10
impossible 
[align=left]Source[/align]University of Waterloo Local Contest 2005.02.05

问题链接HDU1194 POJ2301 UVA10812 ZOJ2388 Beat the Spread!

问题简述:(略)
问题分析:这是一个数学计算问题,看程序解释。
程序说明:(略)
题记:(略)

参考链接:(略)

AC的C语言程序如下:/* HDU1194 POJ2301 UVA10812 ZOJ2388 Beat the Spread! */

#include <stdio.h>

int main(void)
{
int n, s, d; /* s表示和,d表示差的绝对值 */

scanf("%d", &n);
while(n--) {
scanf("%d%d", &s, &d);

if(s < d)
/* 数是整数,和不可能小于差的绝对值 */
printf("impossible\n");
else if((s + d) % 2 != 0)
/* 和与绝对值的差必须同奇偶 */
printf("impossible\n");
else
/* 设x,y(x>y)的和与差分别是s和d,那么x=(s+d)/2,y=(s-d)/2 */
printf("%d %d\n", (s + d) / 2, (s - d) / 2);
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: