The Legend of Freya the Frog
Problem
Freya the Frog is traveling on the 2D coordinate plane. She is currently at point (0,0) and wants to go to point (x,y). In one move, she chooses an integer d such that 0≤d≤k and jumps d spots forward in the direction she is facing.
Initially, she is facing the positive x direction. After every move, she will alternate between facing the positive x direction and the positive y direction (i.e., she will face the positive y direction on her second move, the positive x direction on her third move, and so on).
What is the minimum amount of moves she must perform to land on point (x,y)?
Input
The first line contains an integer t t t ( 1 ≤ t ≤ 1 0 4 ) (1≤t≤10^4) (1≤t≤104) — the number of test cases.
Each test case contains three integers x x x, y y y, and k k k ( 0 ≤ x , y ≤ 1 0 9 , 1 ≤ k ≤ 1 0 9 ) (0≤x,y≤10^9,1≤k≤10^9) (0≤x,y≤109,1≤k≤109).
Output
For each test case, output the number of jumps Freya needs to make on a new line.
Example
Input
3
9 11 3
0 10 8
1000000 100000 10
Output
8
4
199999
Note
In the first sample, one optimal set of moves is if Freya jumps in the following way: (0,0) → (2,0) → (2,2) → (3,2) → (3,5) → (6,5) → (6,8) → (9,8) → (9,11). This takes 8 jumps.
Code
// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t;
cin>>t;
while(t--)
{
ll x,y,k;
cin>>x>>y>>k;
ll ans=max((x+k-1)/k*2-1,(y+k-1)/k*2);
cout<<ans<<endl;
}
return 0;
}