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:
23 3
3 4
Output:
67
题解
画图找规律。
#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
- Codechef Reach The Point
- REACH
- codechef The Army
- (codechef)The Next Palindrome
- CODECHEF Fill The Matrix
- codechef The Lead Game 题解
- codechef The Morning Commute 题解
- codechef Closing the Tweets 题解
- 【CodeChef】Holes in the text
- 【Codechef】Tiptoe through the tulips
- 【CodeChef】 Queries on the String
- CodeChef Protecting The Poison【贪心】
- CodeChef PROTEPOI Protecting The Poison
- Build Custom Activities To Extend The Reach Of Your Workflows
- IPTV and Internet Video: Expanding the Reach of Television Broadcasting
- AIX telnet: connect: Cannot reach the destination network.
- Count ways to reach the n’th stair
- CodeChef
- hadoop MapReduce join
- chrome 字体 小 12PX 强行转换
- 多边形面积公式证明
- LUCENE 3.6 学习笔记
- Servlet 工作原理解析
- Codechef Reach The Point
- CentOS下安装 ImageMagick时 缺失 freetype的解决方法
- DOM基本属性笔记
- apache 2.4.9 配置
- LeetCode Reverse Words in String (Java)
- 分析模式 - 度量与测绘
- Add Binary
- C9_指针高级
- iOS面试总结 - 3. iOS高级面试题