1065. A+B and C (64bit) (20)
2024-09-29 05:12:39
Given three integers A, B and C in [-263, 263], 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
Sample Output:
Case #1: false
Case #2: true
Case #3: false
//long long 有效位为[-2^63,2^63,),如果a,b取到临界点,会出现溢出。
// A+B最大为 2^64-2(左开右闭),(2^64-2)%2^63=-2,long long的正溢出的范围为[-2^63,-2]
// 所以A>0,B>0,A+B<0时,为正溢出,结果为true。
//相同long long负溢出范围为[0,2^63],当A<0,B<0,A+B>=0时结果为负
#include<cstdio>
int main(){
int k,Tcase = ; //变量不能用case
scanf("%d",&k);
for(int i = ; i < k; i++){
long long a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
long long res;
res = a + b;
bool flag;
if(a < && b < && res >= ) flag = false; // 负溢出时等号可以取到
else if(a > && b > && res < ) flag = true; //正溢出为true,负溢出为false
else if(res > c) flag = true;
else flag = false;
if(flag == true) printf("Case #%d: true\n",Tcase++);
else printf("Case #%d: false\n",Tcase++);
}
return ;
}
最新文章
- 传统瀑布式&;敏捷开发
- jquery.cookie.js &;&; java后台代码 操作cookie实现记住当前用户输入信息代码
- 找回MSI安装包Win7/Win8管理员身份功能
- BZOJ 3363: [Usaco2004 Feb]Cow Marathon 奶牛马拉松
- 卸载Oracle步骤
- C#中跨线程访问控件问题解决方案
- 【jmeter】关联-正则表达和xpath
- Leaflet实现动态线路
- Taskctl安装及配置Kettle插件
- PHP:自己写的mysql操作类
- 通用redis命令
- UESTC 1034 AC Milan VS Juventus 分情况讨论
- 安全之路 —— C/C++实现利用添加注册表项实现文件自启动
- Android:Unable to find explicit activity class
- 如何将在线电子书保存为pdf格式
- spark的shuffle和原理分析
- 分布式搜索elasticsearch几个概念解析
- Appuim学习路-Appuim介绍
- 在centos7.1上安装systemd
- 安装和使用mongodb
热门文章
- [Python Study Notes]pynput实现对键盘控制与监控
- Class类动态加载类的用法
- 数据库开源框架ormlite
- 【总结整理】地理信息系统GIS的基础坐标知识
- 利用powerdesigner创建表模型后导出sql语句方法,以及报错 Generation aborted due to errors detected during the verification of the model.的解决办法
- webfrom 母版页
- 10、R常用命令
- Luogu 3627 [APIO2009]抢掠计划
- c++线程调用python
- sina 接口 根据ip获取各个国家和地区