Description
给你一个终点(x,y),从(0,0)出发,每步可以向任意方向沿直线走 恰好为R的距离,请你输出到达终点所需的最短步数。
Input
多组数据,每组数据输入R,x,y
1 ≤ R ≤ 105
0 ≤ x, y ≤ 105
(x,y)≠(0,0)
所有输入皆为int型Output
输出结果并换行
Sample Input
3 4 4
2 1 1
2 2 2Sample Output
2
2
2Hint
距离不能恰好走到的情况,可以走折线到达
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
long long R, x, y;
while (scanf("%lld%lld%lld", &R, &x, &y) != EOF)
{
double dis = sqrt(x * x + y * y) / R;
if (sqrt(x * x + y * y) < R) //如果原点到终点的距离小于步长
{
cout << 2 << endl; //则需要走两步
}
else if ((int)dis < dis) //如果dis不能整除,则需多走一步
{
cout << (int)dis + 1 << endl;
}
else //如果dis能整除,则走直线到达
{
cout << (int)dis << endl;
}
}
return 0;
}