【POJ - 2301 】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??
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 40Sample Output
30 10 impossible題目大意:
? ?就是說有倆數x和y,現在告訴你? ? 這兩個數的和a、這兩個數的差的絕對值b。? 問你能否構造出這兩個數,如果沒有符合條件的解,輸出-1,如果有,就從大到小輸出x和y。
解題報告:
? ?水題啊,找個規律,發現如果加和為奇數的話,,肯定是不滿足的啊(證明我也沒細想,反正寫出來之后小范圍測試了一下沒啥問題就交了)
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 2e5 + 5; ll a,b; int main() {int t;cin>>t;while(t--) {scanf("%lld%lld",&a,&b);if(a<b) {puts("impossible");continue;}ll ans1 = (a+b)>>1;if(ans1*2 != (a+b)) {puts("impossible");continue;}ll ans2 = a-ans1;if(ans1 < ans2) swap(ans1,ans2);printf("%lld %lld\n",ans1,ans2);}return 0 ;}?
?
總結
以上是生活随笔為你收集整理的【POJ - 2301 】Beat the Spread! (简单数学)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中信信用卡积分优惠 5倍加速百亿积分大派
- 下一篇: 常见的银行理财术语有哪一些?不可不知的理