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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

【详细讲解】1065 A+B and C (64bit) (20 分)

發布時間:2024/2/28 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【详细讲解】1065 A+B and C (64bit) (20 分) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

立志用最少的代碼做最高效的表達


PAT甲級最優題解——>傳送門


Given three integers A, B and C in [?2^?63?? ,2^?63?? ], you are supposed to tell whether A+B>C.

Input Specification:
The first line of the input gives the positive number of test cases, T (≤10). Then T test cases follow, each consists of a single line containing three integers A, B and C, separated by single spaces.

Output Specification:
For each test case, output in one line Case #X: true if A+B>C, or Case #X: false otherwise, where X is the case number (starting from 1).

Sample Input:
3
1 2 3
2 3 4
9223372036854775807 -9223372036854775808 0
1
2
3
4

Sample Output:
Case #1: false
Case #2: true
Case #3: false


數據溢出為環形, 即263+1=2?632^{63}+1 = 2^{-63}263+1=2?63。 同理:2?63?1=2632^{-63}-1= 2^{63}2?63?1=263

因此考慮兩種情況:
溢出:如果a>0, b>0, 但a+b<0,即為溢出。溢出的值肯定比C大。 反之同理。
不溢出:正常判斷即可。


#include<bits/stdc++.h> using namespace std; using gg = long long; int main() {gg n; scanf("%lld", &n); for(gg i = 1; i <= n; i++) {gg a, b, c;scanf("%lld %lld %lld", &a, &b, &c);gg res = a+b, flag;if(a>0 && b>0 && res<0) flag=true; //都溢出了肯定比C大else if(a<0 && b<0 && res>=0) flag=false;//都溢出了肯定比C小else flag = a+b>c;printf("Case #%lld: %s\n", i, (flag ? "true" : "false")); } return 0; }

耗時:


求贊哦~ (?ω?)

總結

以上是生活随笔為你收集整理的【详细讲解】1065 A+B and C (64bit) (20 分)的全部內容,希望文章能夠幫你解決所遇到的問題。

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