Codechef Reach The Point

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值