-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.cpp
More file actions
executable file
·59 lines (49 loc) · 897 Bytes
/
Copy pathsol.cpp
File metadata and controls
executable file
·59 lines (49 loc) · 897 Bytes
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
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
struct Pt
{
double x, y;
};
void solve()
{
double r;
int n;
cin >> r >> n;
vector<Pt> points;
for (int i = 0; i < n; ++i)
{
Pt p;
cin >> p.x >> p.y;
points.push_back(p);
}
points.push_back(points[0]);
double length = 0.0;
for (int i = 0; i < points.size() - 1; ++i)
{
const Pt &a = points[i];
const Pt &b = points[i + 1];
length += sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double new_length = length - 2.0 * M_PI * r;
if (new_length >= 0)
{
cout << new_length / length << endl;
}
else
{
cout << "Not possible" << endl;
}
}
int main()
{
cout.precision(10);
int n;
cin >> n;
while (n--)
{
solve();
}
return 0;
}