-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.cc
59 lines (51 loc) · 1.43 KB
/
Solution.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define VAR(V,init) __typeof(init) V=(init)
#define FOREACH(I,C) for(VAR(I,(C).begin());I!=(C).end();I++)
#define FOR(I, S, E) for(__typeof(S) I=(S); I < (E); ++I)
void readInt64(int64_t *v) {
scanf("%"SCNd64, v);
}
void printInt64(int64_t v) {
printf("%"PRId64, v);
}
int main(int argc, char *argv[]) {
int64_t r, x, y, x1, y1;
readInt64(&r); readInt64(&x); readInt64(&y); readInt64(&x1); readInt64(&y1);
// 2r * t <= dist - 2r
// 2r * (t+1) <= dist
// 4r^2 * (t+1)^2 <= distSquare
int64_t distSquare = (x - x1)*(x-x1) + (y-y1)*(y-y1);
double dist = sqrt(distSquare);
double t = dist / (2*r) - 1;
int64_t diff = ((int64_t)t+1) * ((int64_t)t+1) * 4 * r * r;
//printf("dist = %lf, t = %lf, (int)t = %d\n", dist, t, (int)t);
//printf("distSquare = ");
//printInt64(distSquare);
//printf("\n");
//printf("diff = ");
//printInt64(diff);
//printf("\n");
if (distSquare == 0) {
printf("0\n");
} else if (4*r*r == distSquare) {
printf("1\n");
} else if (t <= 0 || distSquare == diff) {
printf("%d\n", (int)t + 1);
} else {
printf("%d\n", (int)t + 2);
}
return 0;
}