A - Add Odd or Subtract Even
A - Add Odd or Subtract Even



思路:其实认真观察就能发现,这个与输入的书有关系,且答案为0,1,2。先看相同,不用加减,为0,再看前小后大,因为加奇数减偶数,如果,相差奇数,为1,相差偶数,为2,同理可得前大后小的答案。
代码:
#include<iostream>
#include<cmath>
using namespace std; int main(){
std::ios::sync_with_stdio(false);
int a, b, sum, n;
cin >> n;
while (n--){
cin >> a >> b;
if (a == b)
cout << "0" << endl; else if (a < b){
sum = b - a;
if (sum % 2 == 0)
cout << "2" << endl;
else
cout << "1" << endl;
}
else{
sum = a - b;
if (sum % 2 == 0)
cout << "1" << endl;
else
cout << "2" << endl;
}
}
return 0;
}
A - Add Odd or Subtract Even的更多相关文章
- Codeforce 1311A Add Odd or Subtract Even
Add Odd or Subtract Even time limit per test2 seconds memory limit per test256 megabytes inputstanda ...
- [CF1311A] Add Odd or Subtract Even
Solution a<b, delta=odd, ans=1 a<b, delta=even, ans=2 a=b ans=0 a>b, delta=odd, ans=2 a> ...
- Codeforces Round #624 (Div. 3) A. Add Odd or Subtract Even(水题)
You are given two positive integers aa and bb . In one move, you can change aa in the following way: ...
- deep_learning_Function_tf.add()、tf.subtract()、tf.multiply()、tf.div()
tf.add().tf.subtract().tf.multiply().tf.div()函数介绍和示例 1. tf.add() 释义:加法操作 示例: x = tf.constant(2, dtyp ...
- Codeforces补题2020.2.28(Round624 Div 3)
A.Add Odd or Subtract Even 签到题~ #include<bits/stdc++.h> using namespace std; int T; int a,b; i ...
- Codeforces Round #624 (Div. 3)(题解)
A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...
- HDU 4919 Exclusive or 数学
题意: 定义 \[f(n)=\sum\limits_{i=1}^{n-1}(i\oplus (n-i))\] 求\(f(n),n \leq 10^{500}\) 分析: 这个数列对应OEIS的A006 ...
- 缓冲区溢出利用——捕获eip的傻瓜式指南
[译文] 摘要:为一个简单的有漏洞程序写一个简单的缓冲区溢出EXP,聚焦于遇到的问题和关键性的教训,提供详细而彻底的描述 内容表:1. I pity the fool, who can't smash ...
- [开源].NET数据库访问框架Chloe.ORM
扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...
- Beginning Scala study note(4) Functional Programming in Scala
1. Functional programming treats computation as the evaluation of mathematical and avoids state and ...
随机推荐
- [ZZH]第一篇博客
time: 2022/3/29 20:24 my first blog
- 【GROMACS】分子动力学模拟①——环境搭建
系统环境 Win11 22H2 企业版 开启虚拟化.window subsystem for liunx等虚拟机相关的功能 应用商店中安装WSL2 安装步骤 打开Ubuntu,输入sudo apt f ...
- 错误 C2664 “int fputs(const char *,FILE *)”: 无法将参数 1 从“char”转换为“const char *”解决方法
遇到这个问题,请打开本项目的Properties(属性) -------> Configuration Properties(配置属性) -------->General(常规) ---- ...
- SQL 错误 [1105] [HY000]: errCode = 2, detailMessage = select list expression not produced by aggregation output (missing from GROUP BY clause?): ......
SQL 错误 [1105] [HY000]: errCode = 2, detailMessage = select list expression not produced by aggregati ...
- Visual Studio 安装时,共享组件、工具和SDK的路径无法更改解决方法
Visual Studio 安装时,共享组件.工具和SDK的路径无法更改解决方法 解决方案: 找到电脑中Visual Studio 2019或其他版本的VS 的注册表,删除共享组件.工具和 SDK 的 ...
- Nginx结合tomcat 负载均衡
负载均衡是我们大流量网站要做的一个东西,下面我来给大家介绍在Nginx服务器上进行负载均衡配置方法,希望对有需要的同学有所帮助哦. 负载均衡 先来简单了解一下什么是负载均衡,单从字面上的意思来理解就可 ...
- REST开发(1)
REST风格 REST简介 Rest(Representational State Transfer),表现形式状态转换(访问网络资源的形式) 传统风格资源描述形式 http://localhost/ ...
- 《基于Linux平台实现定时器功能》
1.demo static void sigHandFun(int signum) { struct itimerval itv; itv.it_interval.tv_sec = 5; itv.it ...
- 本地CentOS8 配置ssh免密登录服务器
准备工作: 1.确认本机sshd的配置文件(需要root权限) $ vi /etc/ssh/sshd_config 找到以下内容,并去掉注释符"#" AuthorizedKeysF ...
- MQTT 发布/订阅模式介绍
MQTT 发布/订阅模式 发布订阅模式(Publish-Subscribe Pattern)是一种消息传递模式,它将发送消息的客户端(发布者)与接收消息的客户端(订阅者)解耦,使得两者不需要建立直接的 ...