日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 40

Sample 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! (简单数学)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。