zoukankan      html  css  js  c++  java
  • 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
    ", ff );
        return 0;
    }
    

                 

  • 相关阅读:
    WebForms 开发基础
    Web 开发基础
    Winform MDI窗体容器、权限、简单通讯
    Winform TextBox中只能输入数字的几种常用方法(C#)
    WinForm TreeView递归加载
    窗体四边阴影
    winform 进程,线程
    树状数组 / 二维树状数组
    zkw线段树
    [HNOI2014]世界树
  • 原文地址:https://www.cnblogs.com/yspworld/p/4245402.html
Copyright © 2011-2022 走看看