ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

A题题解

2021-05-01 13:32:26  阅读:159  来源: 互联网

标签:AA BB point 题解 number 1000000 test


题目:

  

We have a point AA with coordinate x=nx=n on OXOX-axis. We'd like to find an integer point BB (also on OXOX-axis), such that the absolute difference between the distance from OO to BB and the distance from AA to BB is equal to kk.

The description of the first test case.

Since sometimes it's impossible to find such point BB, we can, in one step, increase or decrease the coordinate of AA by 11. What is the minimum number of steps we should do to make such point BB exist?

Input

The first line contains one integer tt (1≤t≤60001≤t≤6000) — the number of test cases.

The only line of each test case contains two integers nn and kk (0≤n,k≤1060≤n,k≤106) — the initial position of point AA and desirable absolute difference.

Output

For each test case, print the minimum number of steps to make point BB exist.

Example

Input
6
4 0
5 8
0 1000000
0 0
1 0
1000000 1000000
Output
0
3
1000000
0
1
0
题目要求距离差为K最少步数,首先如果a等于k就不用移动,b可为a点,a小于k,就是k-a步,因为这时a移动到k,b可为0,最短。
如果a大于k,就判断a-k的差,为偶就不用移动,因为如果两数相减为偶,两数就只可能是1.奇奇2.偶偶,如果a为奇,中间可找到
任何一个点,相减使其为小于等于a的奇数,如果a为偶,中间可找到任何一个点,相减使其为小于等于a的偶数。
如果a-k的差为奇,那么a移动一位就变成差为偶的情况
代码:
#include<stdio.h>
int main(){
    int n,a,b;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&a,&b);
        if(a>b){
            if((a-b)%2==0)printf("%d\n",0);
            else printf("%d\n",1);
        }
        else if(a<b)printf("%d\n",b-a);
        else printf("0\n");
    }
    return 0;
} 

 

标签:AA,BB,point,题解,number,1000000,test
来源: https://www.cnblogs.com/TYoUer/p/14724119.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有