forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflowergarden.cpp
61 lines (52 loc) · 985 Bytes
/
flowergarden.cpp
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
60
61
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
ld getdist(ld x1, ld y1, ld x2, ld y2) {
return sqrt(pow(x1-x2,2) + pow(y1-y2,2));
}
bool isprime(int n) {
if(n < 2) {
return false;
}
if(n == 2) {
return true;
}
for(int i = 2; i*i <= n; i++) {
if(n % i == 0) {
return false;
}
}
return true;
}
void solve() {
int n;
cin >> n;
ld maxdist;
cin >> maxdist;
int best = 0;
int curr = 0;
ld dist = 0;
int prevx = 0;
int prevy = 0;
for(int i = 0; i < n; i++) {
int x, y;
cin >> x >> y;
dist += getdist(prevx, prevy, x, y);
prevx = x;
prevy = y;
if(dist <= maxdist) {
curr++;
if(isprime(curr)) {
best = curr;
}
}
}
cout << best << endl;
}
int main() {
int cases;
cin >> cases;
while(cases--) {
solve();
}
}