【HDU】1194 Beat the Spread!
2018-03-19 21:03
465 查看
[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
这道题其实是一道很简单的题,但是要读懂题意,注意细节。题目大概就是已知两个整数的和和差的绝对值,输出这两个整数,大的在前,小的在后。
比如 Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final scores. 第一遍没有AC就是因为没考虑到输出要是整数。
代码:#include <stdio.h>
int main() {
int N,a,b,x1,x2;
scanf("%d",&N);
while (N--) {
scanf("%d %d",&a,&b);
if(a<b)
printf("impossible\n");
else if ((a+b)%2==0&&(a-b)%2==0) //判断要求的x1,x2是不是整数
{
x1=(a+b)/2;
x2=(a-b)/2;
printf("%d %d\n",x1,x2);
}
else
printf("impossible\n");
}
return 0;
}
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
这道题其实是一道很简单的题,但是要读懂题意,注意细节。题目大概就是已知两个整数的和和差的绝对值,输出这两个整数,大的在前,小的在后。
比如 Each test case gives s and d, non-negative integers representing the sum and (absolute) difference between the two final scores. 第一遍没有AC就是因为没考虑到输出要是整数。
代码:#include <stdio.h>
int main() {
int N,a,b,x1,x2;
scanf("%d",&N);
while (N--) {
scanf("%d %d",&a,&b);
if(a<b)
printf("impossible\n");
else if ((a+b)%2==0&&(a-b)%2==0) //判断要求的x1,x2是不是整数
{
x1=(a+b)/2;
x2=(a-b)/2;
printf("%d %d\n",x1,x2);
}
else
printf("impossible\n");
}
return 0;
}
相关文章推荐
- HDU 1194Beat the Spread!
- hdu 1194 Beat the Spread!
- HDU 1194 Beat the Spread!(数学问题呀..)
- HDU 1194 Beat the Spread!
- (hdu 简单题 128道)hdu 1194 Beat the Spread!(已知两个数的和u两个数的差求这两个数)
- HDU1194_Beat the Spread!
- hdu-oj 1194 Beat the Spread!
- hdu 1194 Beat the Spread!(水题)
- POJ 2301 && HDU 1194 Beat the Spread!(水~)
- 杭电 HDU 1194 Beat the Spread!
- HDU1194_Beat the Spread!
- HDU 1194 Beat the Spread! 【水题+细心】
- HDU 1194 - Beat the Spread!
- HDU 1194 Beat the Spread!
- HDU 1194 Beat the Spread!
- HDU 1194 Beat the Spread!(数学)
- hdu1194-Beat the Spread!
- HDOJ1194 Beat the Spread!
- HDOJ 1194 Beat the Spread!
- 1194:Beat the Spread!