UVaOJ 10055 - Hashmat the Brave Warrior
来源:互联网 发布:职业网络打假 编辑:程序博客网 时间:2024/04/30 21:52
AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 0. Getting Started
Description
Hashmat是一个勇敢的战士,他带领着一群年轻士兵从一个地方到另一个地方去与敌人打仗。
Hashmat的士兵从未比敌人多过,所以在他与敌人战斗之前,他会计算自己与敌人的兵力差距。
根据兵力差距来决定是否和敌人战斗。
Input
每一行输入包括两个整数,这两个整数表示Hashmat军队的士兵数量和敌人军队的士兵数量,反之亦然。
输入的数不大于2^32,并且输入以文件结尾。
Output
对于每行输入,输出Hashmat与敌人的兵力差距,每个结果单独占一行。
Type
implementation
Analysis
该题包含了两个陷阱。
第一个陷阱在于“or vice versa”这句话,表示“反之亦然”,并且勇士的兵是一定比对方少。
说明勇士的兵数,不一定是先输入还是后输入,反正是比较少的那个。
不过如果,一开始就看成求两数差的绝对值的话,没太大关系。
第二个陷阱在于输入的数字,不超过2^32。
int最大是2^31 - 1,而用unsigned依然会超。
因为unsigned最大是2^32 - 1,仍然放不下2^32……
所以这题的数据类型得定义成long long。
Solution
// UVa 10055// Hashmat the Brave Warrior// by A Code Rabbit#include <cstdio>typedef long long LL;LL a, b;int main() { while (scanf("%lld%lld", &a, &b) != EOF) { printf("%lld\n", a > b ? a - b : b - a); } return 0;}
- UVaOJ 10055 - Hashmat the Brave Warrior
- UVaOJ 10055 - Hashmat the Brave Warrior
- [UvaOJ - Getting Started] 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055-Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055-Hashmat the Brave Warrior
- 10055 - Hashmat the Brave Warrior
- 10055-Hashmat the brave warrior
- 10055 - Hashmat the Brave Warrior
- Hashmat the Brave Warrior
- Hashmat the brave warrior
- RabbitMQ 消息队列服务器 进程通讯
- RabbitMQ的使用
- javascript 转换Json字符串为JSON对象
- Linux下的虚拟摄像头
- 深入解析printf/spintf/snprintf中的类型转换
- UVaOJ 10055 - Hashmat the Brave Warrior
- Ubuntu 中软件的安装、卸载以及查看的方法总结
- 搭建Android开发环境
- CGContext小记
- 如何复制GSM SIM卡
- Qt点滴
- iOS6 App Store 更新:扑克式App搜索结果布局 马太效应加重!
- 各大解析漏洞总结
- Java 编程思想(第四版)学习笔记(6)访问权限控制