zoukankan      html  css  js  c++  java
  • CF Amr and Pins (数学)

    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 rxyxy' (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).

    把两个圆抽象成两个点,两个点的坐标是圆心,那么最短的距离就是这两点的距离,而每次能移动的最大距离是2R,所以每次先移动那么多,直到最后接近的时候,又从某个不同的点开始旋转。说实话我无法证明最后这个旋转一定能到达,但是凭着直觉就敲上去了,结果1A,运气吧。

     1 #include <bits/stdc++.h>
     2 using    namespace    std;
     3 
     4 int    main(void)
     5 {
     6     double    s,r;
     7     double    x_1,y_1,x_2,y_2;
     8     int    ans;
     9 
    10     scanf("%lf",&r);
    11     scanf("%lf%lf%lf%lf",&x_1,&y_1,&x_2,&y_2);
    12     s = sqrt(pow(x_1 - x_2,2) + pow(y_1 - y_2,2));
    13 
    14     ans = s / (2 * r);
    15     if(ans * r * 2 < s)
    16         ans += 1;
    17     printf("%d
    ",ans);
    18 
    19     return    0;
    20 }
  • 相关阅读:
    Service Broker between two instance
    第一次调用Web service响应速度慢的解决办法
    MVC静态化
    WinFrom Exception Handler
    The difference for ROW_NUMBER/RANK/DENSE_RANK/NTILE
    字符编码
    TSQL中的参数与变量
    Entity Framework Power Tool
    Use ActionFilterAttribute to check user logging
    SiteFactory技术实现QQ群19452522用户交流贴
  • 原文地址:https://www.cnblogs.com/xz816111/p/4467278.html
Copyright © 2011-2022 走看看