Yet Another Two Integers Problem

举报
辰chen 发表于 2022/06/15 00:40:21 2022/06/15
【摘要】 文章目录 一、Yet Another Two Integers Problem总结 一、Yet Another Two Integers Problem 本题链接:Yet Anothe...


一、Yet Another Two Integers Problem

本题链接Yet Another Two Integers Problem

题目
A. Yet Another Two Integers Problem
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given two integers a and b.

In one move, you can choose some integer k from 1 to 10 and add it to a or subtract it from a. In other words, you choose an integer k∈[1;10] and perform a:=a+k or a:=a−k. You may use different values of k in different moves.

Your task is to find the minimum number of moves required to 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≤2⋅1e4) — the number of test cases. Then t test cases follow.

The only line of the test case contains two integers a and b (1≤a,b≤1e9).

Output
For each test case, print the answer: the minimum number of moves required to obtain b from a.

Example
input
6
5 5
13 42
18 4
1337 420
123456789 1000000000
100500 9000
output
0
3
2
92
87654322
9150

Note
In the first test case of the example, you don’t need to do anything.

In the second test case of the example, the following sequence of moves can be applied: 13→23→32→42 (add 10, add 9, add 10).

In the third test case of the example, the following sequence of moves can be applied: 18→10→4 (subtract 8, subtract 6).

本博客给出本题截图
在这里插入图片描述
题意:给出两个数ab,每次我们可以把b加上或减去(1~10)中的任何一个数字,问最少操作几步可以把数字b变成数字a

AC代码

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int t;
    cin >> t;
    
    while (t -- )
    {
        int a, b;
        cin >> a >> b;
        
        int t = abs(a - b);
        if (t % 10) 
            cout << t / 10 + 1 << endl;
        else cout << t / 10 << endl;
    }
    
    return 0;
}

  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

总结

水题,不解释

文章来源: chen-ac.blog.csdn.net,作者:辰chen,版权归原作者所有,如需转载,请联系作者。

原文链接:chen-ac.blog.csdn.net/article/details/117886315

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。