Codechef Reach The Point

来源:互联网 发布:js怎么调用java的方法 编辑:程序博客网 时间:2024/05/18 21:44

Problem Description

Recently Chef bought a bunch of robot-waiters. And now he needs to know how much to pay for the electricity that robots use for their work. All waiters serve food from the kitchen (which is in the point (0, 0)) and carry it to some table (which is in some point (x, y)) in a shortest way. But this is a beta version of robots and they can only do the next moves: turn right and make a step forward or turn left and make a step forward. Initially they look in direction of X-axis. Your task is to calculate for each query the number of moves they’ll do to reach corresponding table.

Input

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. For each test case there is a sing line containing two space-separated integers - x and y.

Output

For each test case, output a single line containing number of moves that robot will make to reach point (x, y)

Constraints

1 ≤ T ≤ 105
-109 ≤ x, y ≤ 109


Example

Input:

2
3 3
3 4

Output:

6
7

题解

画图找规律。

#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<cmath>using namespace std;int x,y,T,ans,t;int main(){scanf("%d",&T);while(T--)   {scanf("%d%d",&x,&y);    x=abs(x); y=abs(y);    if(x==y||x+1==y) ans=x+y;    else if(x>y)       {t=(x-y)&1;    ans=(x<<1)+t;   }else   {t=(y-x)&1;    ans=(y<<1)-t;   }printf("%d\n",ans);   }return 0;}
0 0
原创粉丝点击