立志用最少的代码做最高效的表达


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 分)相关推荐

  1. PATA 1065 A+B and C (64bit) (20分)

    PATA 1065 A+B and C (64bit) (20分) 题目描述:Given three integers A, B and C in [−2^​63, 2^​63], you are s ...

  2. 1065 A+B and C (64bit) (20 分)【难度: 简单 / 思维 高精度】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336 方法一: 用高精度的板子写一下是可以的,不过 ...

  3. 【PAT甲级 大数运算】1065 A+B and C (64bit) (20 分) Python 全部AC

    题目 初学python,第一次用python刷oj,挑了个简单题试试手. 在大数运算方面,python没有数的大小限制,简直开挂. total = int(input()) for i in rang ...

  4. 【PAT甲级 大整数BigInteger】1065 A+B and C (64bit) (20 分) Java 全部AC

    题目 在有些方面,比如大整数的处理,不得不佩服Java,好用没的说,像开挂一样 题解 Java import java.math.BigInteger; import java.util.Scanne ...

  5. PAT 1065 A+B and C (64bit) (20)

    1065. A+B and C (64bit) (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 HOU, Qiming G ...

  6. PAT A1065 A+B and C (64bit) (20 分)

    AC代码 #include <cstdio>int main() {#ifdef ONLINE_JUDGE#elsefreopen("1.txt", "r&q ...

  7. 【题意+推导讲解】1031 Hello World for U (20 分)_15行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given any string of N (≥5) characters, you are asked to form the ...

  8. 【详细分析】1023 Have Fun with Numbers (20 分)_20行代码AC

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Notice that the number 123456789 is a 9-digit number consisting e ...

  9. (C语言最详细解析)1003 我要通过! (20 分)

    1003 我要通过! (20 分) "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的"答案正确"大派送 -- 只要读入的字符串满足下列条件 ...

最新文章

  1. alias重启终端失效的问题
  2. 还只是 39 岁!一个天才年轻程序员的陨落
  3. 用C语言解“打印九九乘法表”题
  4. python的基本结构_python基础--结构篇
  5. 铺地毯pascal程序
  6. 关于flex布局,我大多数常用的几个点
  7. uva 10622——Perfect P-th Powers
  8. “我没搞懂元宇宙,但一天能赚9w块”
  9. vue 多点触控手势_手写 Vue 手势组件__Vue.js
  10. visio中虚线粘贴到word中变实线的解决办法(转)
  11. vue php 加载速度,Vue加载优化,速度提高一倍。
  12. spire.pdf系列文章
  13. 13.xsi:schemaLocation详解
  14. react 逆地理 高德地图_给高德新版地图点赞!出行服务竟然如此智能
  15. Linux中ctrl+z 和trl+c的区别以及jobs、bg、fg命令
  16. 雪亮工程视频监控应用系统解决方案
  17. 人脸数据库汇总 (来自网络)
  18. [益智]:猴子搬香蕉
  19. 用java写一个图书类book
  20. vmware虚拟机安装win7_VMware虚拟机安装教程

热门文章

  1. Chromium Android编译指南
  2. 第12讲:Ajax 的原理和解析
  3. python time,datetime当前时间,昨天时间,时间戳和字符串的转化
  4. Kafka发送超过broker限定大小的消息时Client和Broker端各自会有什么异常?
  5. 当AI成为基础资源,360OS 发力在线教育的重心——专访360OS张焰
  6. Linux下 /dev/null 21 相关知识说明
  7. 利用nginx搭建RTMP视频点播、直播、HLS服务器
  8. VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射
  9. centos 7 安装 npm 工具
  10. KVM更改虚拟机默认存储路径