Add Odd or Subtract Even

time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

You are given two positive integers a and b.

In one move, you can change a in the following way:

Choose any positive odd integer x (x>0) and replace a with a+x;

choose any positive even integer y (y>0) and replace a with a−y.

You can perform as many such operations as you want. You can choose the same numbers x and y in different moves.

Your task is to find the minimum number of moves required to obtain b from a. It is guaranteed that you can always obtain b from a.

You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1≤t≤104) — the number of test cases.

Then t test cases follow. Each test case is given as two space-separated integers a and b (1≤a,b≤109).

Output

For each test case, print the answer — the minimum number of moves required to obtain b from a if you can perform any number of moves described in the problem statement. It is guaranteed that you can always obtain b from a.

Example

input

5

2 3

10 10

2 4

7 4

9 3

output

1

0

2

2

1

Note

In the first test case, you can just add 1.

In the second test case, you don’t need to do anything.

In the third test case, you can add 1 two times.

In the fourth test case, you can subtract 4 and add 1.

In the fifth test case, you can just subtract 6.

分差的奇偶性,和大小


#include <bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while (t--)
{ int a,b,c;
cin>>a>>b;
if(a==b) cout<<0<<endl;
else if(a>b)
{
if((a-b)%2==0)cout<<1<<endl;
else cout<<2<<endl;
}
else { if((b-a)%2==0)cout<<2<<endl;
else cout<<1<<endl;
}
}
}

Codeforce 1311A Add Odd or Subtract Even的更多相关文章

  1. [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> ...

  2. 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: ...

  3. 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 ...

  4. codeforce 1188A1 Add on a Tree 树

    题意:给你一个树,有一种操作,选择两个叶子节点,然后把这两个叶子节点间的路径全部加或减一个值.问你给出的树上的每一条边经过若干次操作是否可以为任意值. 分析:画几个图后可以发现,如果树中存在一个点的度 ...

  5. 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 ...

  6. Codeforces Round #624 (Div. 3)(题解)

    A. Add Odd or Subtract Even 思路: 相同直接为0,如果两数相差为偶数就为2,奇数就为1 #include<iostream> #include<algor ...

  7. HDU 4919 Exclusive or 数学

    题意: 定义 \[f(n)=\sum\limits_{i=1}^{n-1}(i\oplus (n-i))\] 求\(f(n),n \leq 10^{500}\) 分析: 这个数列对应OEIS的A006 ...

  8. 缓冲区溢出利用——捕获eip的傻瓜式指南

    [译文] 摘要:为一个简单的有漏洞程序写一个简单的缓冲区溢出EXP,聚焦于遇到的问题和关键性的教训,提供详细而彻底的描述 内容表:1. I pity the fool, who can't smash ...

  9. [开源].NET数据库访问框架Chloe.ORM

    扯淡 13年毕业之际,进入第一家公司实习,接触了 EntityFramework,当时就觉得这东西太牛了,访问数据库都可以做得这么轻松.优雅!毕竟那时还年轻,没见过世面.工作之前为了拿个实习机会混个工 ...

随机推荐

  1. qq群排名靠前最新方法

    QQ群排名这几年是越来越火,因为很多灰产业都选择做QQ群排名,毕竟没有那么严,那么要做QQ群排名虽然不难,但是还是需要一点技术和软件的. https://url.cn/5JbR4C8 QQ群排名分为如 ...

  2. MTK Android [输入法]客制化系统默认输入法-搜狗输入法

    1.frameworks/base/packages/SettingsProvider/res/values/defaults.xml <!--Sogou input method is use ...

  3. JAVA debug 断点调试

    更多调试参看 https://www.cnblogs.com/yjd_hycf_space/p/7483471.html 先编译好要调试的程序.1.设置断点 选定要设置断点的代码行,在行号的区域后面单 ...

  4. JUC——检视阅读

    JUC--检视阅读 参考资料 JUC知识图参考 JUC框架学习顺序参考 J.U.C学习总结参考,简洁直观 易百并发编程,实践操作1,不推荐阅读,不及格 JUC文章,带例子讲解,可以学习2 Doug L ...

  5. mysql添加,授权,删除用户以及连接数据库Can't connect to MySQL server on '192.168.31.106' (113)错误排查

    centos7下面操作mysql添加,授权,删除用户 添加用户 以root用户登录数据库,运行以下命令: create user test identified by '; 上面创建了用户test,密 ...

  6. 【python实现卷积神经网络】全连接层实现

    代码来源:https://github.com/eriklindernoren/ML-From-Scratch 卷积神经网络中卷积层Conv2D(带stride.padding)的具体实现:https ...

  7. [总结]最小生成树之Kruskal算法

    目录 一.最小生成树的相关知识 1. 树的性质 2. 生成树 3. 最小生成树 4. 最小生成树的性质 二.Kruskal算法求最小生成树 1. 核心思想 2. 具体流程 3. 图示 4. 代码实施 ...

  8. 【图解】你还在为 TCP 重传、滑动窗口、流量控制、拥塞控制发愁吗?看完图解就不愁了

    每日一句英语学习,每天进步一点点: 前言 前一篇「硬不硬你说了算!近 40 张图解被问千百遍的 TCP 三次握手和四次挥手面试题」得到了很多读者的认可,在此特别感谢你们的认可,大家都暖暖的. 来了,今 ...

  9. H - Bear and Three Balls

    Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one bal ...

  10. 基于Python的Webservice开发(四)-泛微OA的SOAP接口

    一.功能需求 泛微e-cology可以在流程中调用Webservice接口实现与其他系统的联动等复杂功能.但是目前泛微文档中仅提供了调用的方法,但是没有关于接口的相关开发信息. 本次案例是用Pytho ...