codeforcfes Codeforces Round #287 (Div. 2) B. Amr and Pins

本文介绍了一道关于通过旋转移动圆心至目标位置的问题。利用计算几何原理,给出了高效的求解算法,即通过计算两圆心间的距离并除以圆直径得出最小移动次数。
B. Amr and Pins
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Amr loves Geometry. One day he came up with a very interesting problem.

Amr has a circle of radius r and center in point (x, y). He wants the circle center to be in new position (x', y').

In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin by any angle and finally remove the pin.

Help Amr to achieve his goal in minimum number of steps.

Input

Input consists of 5 space-separated integers r, x, y, x' y' (1 ≤ r ≤ 105,  - 105 ≤ x, y, x', y' ≤ 105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively.

Output

Output a single integer — minimum number of steps required to move the center of the circle to the destination point.

Sample test(s)
Input
2 0 0 0 4
Output
1
Input
1 1 1 4 4
Output
3
Input
4 5 6 5 6
Output
0
Note

In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).

 

  题目分析:一个半径为r,圆心在(x, y)处的圆,在圆的轮廓上上随意找一点作为数轴旋转移动该圆,问至少要经过多少次移动,才可以到达指定的圆心(x', y')。

  注意一下数据类型的溢出问题。计算两个圆心之间的距离,取 dis/(r*2)的上限整数就可以了。比如如果结果=3.5,那就输出4.

  代码如下:

             

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;
double r;
double dis(double x, double y, double a, double b)
{
    return  sqrt( ((x-a)*(x-a)+(y-b)*(y-b))/(r*r*4.0) );
}

int main()
{

    double x, y;
    double a, b;
    double dd;
    scanf("%lf %lf %lf %lf %lf", &r, &x, &y, &a, &b);
    dd=dis(x, y, a, b);

    int ff=(int)ceil(dd);
    printf("%d\n", ff );
    return 0;
}

 

             

转载于:https://www.cnblogs.com/yspworld/p/4245402.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值