[结题报告]10812 - Beat the Spread! Time limit: 3.000 seconds
2013-02-19 14:46
411 查看
Problem D: Beat the Spread!
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?
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. 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
Output for Sample Input
30 10 impossible 参考代码: 这道题给定2个数的和和差,需要求出这2个数,我们可以得到2个方程:x+y=a;x-y=b;联立可得到x=(a+b)/2;y=(a-b)/2;而通过联系实际我们可以知道:1.分数不可能为负数.(这点题目已告知).2.比赛分数一定为整数.注意到这两点,这题就能解出.
#include"stdio.h" main() {long n,a,b,x,y,s,flag; scanf("%ld",&n); while(n--) {scanf("%ld%ld",&a,&b); flag=0; x=(a+b)/2; y=(a-b)/2; s=a+b; if(s%2!=0) printf("impossible\n"); //a+b若为奇数,则x讲不会是整数。 else if(x<0||y<0) printf("impossible\n"); else printf("%ld %ld\n",x,y); } }
相关文章推荐
- [结题报告]100 - The 3n + 1 problem Time limit: 3.000 seconds
- [结题报告]10055 - Hashmat the Brave Warrior Time limit: 3.000 seconds
- [解题报告]Beat the Spread!
- 10812 - Beat the Spread!
- UVa 10812 Beat the Spread!
- 10812 - Beat the Spread!
- UVa 10812 - Beat the Spread!
- HDU1194 POJ2301 UVA10812 ZOJ2388 Beat the Spread!【数学】
- UVa 10812 - Beat the Spread!
- UVa 10812 - Beat the Spread!
- [结题报告]11479 - Is this the easiest problem? Time limit: 1.000 seconds
- [结题报告]458 - The Decoder Time limit: 3.000 seconds
- UVa 10812 Beat the Spread! (陷阱)
- [结题报告]686 - Goldbach's Conjecture (II) Time limit: 3.000 seconds
- HDU 1194 Beat the Spread! 【水题+细心】
- hdu1194-Beat the Spread!
- 杭电 1194 Beat the Spread!
- POJ 2301 Beat the Spread!
- ACM HDU 1194 Beat the Spread!(简单的水题)
- ZOJ 2388 Beat the Spread!