-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10263.cpp
More file actions
95 lines (83 loc) · 2.02 KB
/
10263.cpp
File metadata and controls
95 lines (83 loc) · 2.02 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/**
* ____
* ____ ___ ____ ________ __/ __/
* / __ `__ \/ __ `/ ___/ / / / /_
* / / / / / / /_/ / / / /_/ / __/
* /_/ /_/ /_/\__,_/_/ \__,_/_/
*
* @link : https://the-redback.com
*/
#include <bits/stdc++.h>
using namespace std;
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define pp pop_back
#define inf 10e9 // 10^9
#define meminf 100
#define eps 10e-9
#define NN 1000000
struct P {
double x, y;
P(double X, double Y) {
x = X;
y = Y;
}
};
vector<P> v;
P MV(P a, P b) { return P(b.x - a.x, b.y - a.y); }
double DP(P a, P b) { return a.x * b.x + a.y * b.y; }
double A(P a) { return sqrt(a.x * a.x + a.y * a.y); }
P ADD(P a, P b) { return P(a.x + b.x, a.y + b.y); }
P CV(P a, P b, double l) {
b = MV(a, b);
return ADD(a, P(b.x * l / A(b), b.y * l / A(b)));
}
double MAX = inf;
P ans(0, 0);
P go(P a, P b, P c) {
if (DP(MV(a, b), MV(a, c)) <= 0) {
if (A(MV(a, c)) < MAX) {
MAX = A(MV(a, c));
return a;
}
return ans;
}
if (DP(MV(b, a), MV(b, c)) <= 0) {
if (A(MV(b, a)) < MAX) {
MAX = A(MV(b, a));
return b;
}
return ans;
}
double l;
l = DP(MV(a, b), MV(a, c)) / A(MV(a, b));
double ac = A(MV(a, c));
double res = sqrt((ac * ac) - (l * l));
if (res < MAX) {
MAX = res;
return CV(a, b, l);
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
int t = 1, tc;
int i, j, k, l, m, n;
double x, y, z, u, w, xx, yy, zz, d;
double aa, bb, cc, dd;
// cin>>tc;
while (cin >> xx >> yy >> n) {
P p(0, 0);
for (i = 0; i <= n; i++) {
cin >> p.x >> p.y;
v.pb(p);
}
MAX = inf;
for (i = 1; i < v.size(); i++) {
ans = go(v[i - 1], v[i], P(xx, yy));
}
v.clear();
printf("%.4lf\n%.4lf\n", ans.x, ans.y);
}
return 0;
}