日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

【POJ - 2301 】Beat the Spread! (简单数学)

發(fā)布時間:2023/12/10 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ - 2301 】Beat the Spread! (简单数学) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題干:

?

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

題目大意:

? ?就是說有倆數(shù)x和y,現(xiàn)在告訴你? ? 這兩個數(shù)的和a、這兩個數(shù)的差的絕對值b。? 問你能否構(gòu)造出這兩個數(shù),如果沒有符合條件的解,輸出-1,如果有,就從大到小輸出x和y。

解題報告:

? ?水題啊,找個規(guī)律,發(fā)現(xiàn)如果加和為奇數(shù)的話,,肯定是不滿足的啊(證明我也沒細(xì)想,反正寫出來之后小范圍測試了一下沒啥問題就交了)

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

?

?

總結(jié)

以上是生活随笔為你收集整理的【POJ - 2301 】Beat the Spread! (简单数学)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。