当前位置 : 主页 > 编程语言 > c语言 >

Codeforces Round #287 (Div. 2) B. Amr and Pins 计算几何(水题)

来源:互联网 收集:自由互联 发布时间:2023-09-07
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

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.

Examples
inputCopy
2 0 0 0 4
outputCopy
1
inputCopy
1 1 1 4 4
outputCopy
3
inputCopy
4 5 6 5 6
outputCopy
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).

唯一注意的一点的是 eps 设定的小一点,1e-7这样的;
之前设为 eps=1e-4 就wa37 ;
之前做的一道题居然是 eps 小的AC不了,调大才可以。。。( md…)

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<string>
#include<bitset>
#include<ctime>

typedef long long ll;
using namespace std;
typedef unsigned long long int ull;
#define maxn 300005
#define ms(x) memset(x,0,sizeof(x))
#define Inf 0x7fffffff
#define inf 0x3f3f3f3f
const long long int mod = 1e9 + 7;
#define pi acos(-1.0)
#define pii pair<int,int>
#define eps 1e-7
#define pll pair<ll,ll>



ll quickpow(ll a, ll b) {
    ll ans = 1;
    a = a % mod;
    while (b > 0) {
        if (b % 2)ans = ans * a;
        b = b / 2;
        a = a * a;
    }
    return ans;
}

int gcd(int a, int b) {
    return b == 0 ? a : gcd(b, a%b);
}


int main()
{
    ios::sync_with_stdio(false);
    ll r, x1, x2, y1, y2;
    cin >> r >> x1 >> y1 >> x2 >> y2;
    double dis = 1.0*sqrt((x2 - x1)*(x2 - x1)*1.00000 + (y2 - y1)*(y2 - y1)*1.00000);
    ll st = dis;
    //cout << st * 1.0 << ' ' << 1.0000*dis << endl;
    if (abs(st*1.0 - dis) <= eps) {
        if (st % (2 * r) == 0) {
            cout << st / (2 * r) << endl;
        }
        else {
            cout << st / (2 * r) + 1 << endl;
        }
    }
    else {
        if (st % (2 * r) == 0) {
            cout << st / (2 * r) + 1 << endl;
        }
        else {
            cout << st / (2 * r) + 1 << endl;
        }
    }
}
网友评论