【详细讲解】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
4Sample 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 分)相关推荐
- 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 ...
- 1065 A+B and C (64bit) (20 分)【难度: 简单 / 思维 高精度】
https://pintia.cn/problem-sets/994805342720868352/problems/994805406352654336 方法一: 用高精度的板子写一下是可以的,不过 ...
- 【PAT甲级 大数运算】1065 A+B and C (64bit) (20 分) Python 全部AC
题目 初学python,第一次用python刷oj,挑了个简单题试试手. 在大数运算方面,python没有数的大小限制,简直开挂. total = int(input()) for i in rang ...
- 【PAT甲级 大整数BigInteger】1065 A+B and C (64bit) (20 分) Java 全部AC
题目 在有些方面,比如大整数的处理,不得不佩服Java,好用没的说,像开挂一样 题解 Java import java.math.BigInteger; import java.util.Scanne ...
- 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 ...
- PAT A1065 A+B and C (64bit) (20 分)
AC代码 #include <cstdio>int main() {#ifdef ONLINE_JUDGE#elsefreopen("1.txt", "r&q ...
- 【题意+推导讲解】1031 Hello World for U (20 分)_15行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Given any string of N (≥5) characters, you are asked to form the ...
- 【详细分析】1023 Have Fun with Numbers (20 分)_20行代码AC
立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 Notice that the number 123456789 is a 9-digit number consisting e ...
- (C语言最详细解析)1003 我要通过! (20 分)
1003 我要通过! (20 分) "答案正确"是自动判题系统给出的最令人欢喜的回复.本题属于 PAT 的"答案正确"大派送 -- 只要读入的字符串满足下列条件 ...
最新文章
- alias重启终端失效的问题
- 还只是 39 岁!一个天才年轻程序员的陨落
- 用C语言解“打印九九乘法表”题
- python的基本结构_python基础--结构篇
- 铺地毯pascal程序
- 关于flex布局,我大多数常用的几个点
- uva 10622——Perfect P-th Powers
- “我没搞懂元宇宙,但一天能赚9w块”
- vue 多点触控手势_手写 Vue 手势组件__Vue.js
- visio中虚线粘贴到word中变实线的解决办法(转)
- vue php 加载速度,Vue加载优化,速度提高一倍。
- spire.pdf系列文章
- 13.xsi:schemaLocation详解
- react 逆地理 高德地图_给高德新版地图点赞!出行服务竟然如此智能
- Linux中ctrl+z 和trl+c的区别以及jobs、bg、fg命令
- 雪亮工程视频监控应用系统解决方案
- 人脸数据库汇总 (来自网络)
- [益智]:猴子搬香蕉
- 用java写一个图书类book
- vmware虚拟机安装win7_VMware虚拟机安装教程
热门文章
- Chromium Android编译指南
- 第12讲:Ajax 的原理和解析
- python time,datetime当前时间,昨天时间,时间戳和字符串的转化
- Kafka发送超过broker限定大小的消息时Client和Broker端各自会有什么异常?
- 当AI成为基础资源,360OS 发力在线教育的重心——专访360OS张焰
- Linux下 /dev/null 21 相关知识说明
- 利用nginx搭建RTMP视频点播、直播、HLS服务器
- VirtualBox虚拟机网络环境解析和搭建-NAT、桥接、Host-Only、Internal、端口映射
- centos 7 安装 npm 工具
- KVM更改虚拟机默认存储路径