-
Notifications
You must be signed in to change notification settings - Fork 0
/
fifa_fafa.cpp
164 lines (144 loc) · 3.98 KB
/
fifa_fafa.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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// #include <fstream>
// #include <iostream>
// #include <string>
// #include <complex>
// #include <math.h>
// #include <set>
// #include <vector>
// #include <map>
// #include <queue>
// #include <stdio.h>
// #include <stack>
// #include <algorithm>т мом
// #include <list>
// #include <ctime>
// #include <memory.h>
// #include <assert.h>
// #define y0 sdkfaslhagaklsldk
// #define y1 aasdfasdfasdf
// #define yn askfhwqriuperikldjk
// #define j1 assdgsdgasghsf
// #define tm sdfjahlfasfh
// #define lr asgasgash
// #define norm asdfasdgasdgsd
// #define have adsgagshdshfhds
// #define ends asdgahhfdsfshdshfd
// #define eps 1e-8
// #define M_PI 3.141592653589793
// #define bsize 512
// #define ldouble long double
// using namespace std;
// #define bs 1000000007
// const int N = 400031;
// long double R,x1,y1,x2,y2;
// long double get_dist(long double x,long double y){
// return sqrt(x*x+y*y);
// }
// bool outside(){
// return get_dist(x2,y2)>R;
// }
// void show_answer(long double x,long double y,long double r){
// x+=x1;
// y+=y1;
// cout.precision(20);
// cout<<fixed<<x<<" "<<y<<" "<<r<<endl;
// }
// int main(){
// // freopen("apache.in","r",stdin);
// // freopen("apache.out","w",stdout);
// //freopen("input.txt", "r", stdin);
// //freopen("output.txt", "w", stdout);
// ios_base::sync_with_stdio(0);
// // cin.tie(0);
// cin>>R>>x1>>y1>>x2>>y2;
// x2-=x1;
// y2-=y1;
// if (outside()){
// show_answer(0,0,R);
// }
// else
// {
// long double D=get_dist(x2,y2);
// long double dir=atan2(y2,x2);
// dir=dir+M_PI;
// long double diam=R+D;
// long double rad=diam/2;
// rad-=D;
// long double ax=rad*cos(dir);
// long double ay=rad*sin(dir);
// //cout.precision(20);
// show_answer(ax,ay,rad+D);
// }
// // cin.get(); cin.get();
// return 0;
// }
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const double eps = 1e-9;
double x1, x2, Y1, y2, x, y, R;
typedef pair<double, double> point;
struct Circle {
point center;
double radius;
Circle(point p, double r): center(p), radius(r) {}
};
struct Line {
double m, c;
Line(double m_, double c_): m(m_), c(c_){}
double getYCorrespoindingTo(double x) {
return m*x + c;
}
};
struct LineCircleInterSection {
point p1, p2, p;
double a, b, c;
LineCircleInterSection(Line l, Circle cr) {
a = 1 + 1.0f * pow(l.m, 2);
b = 2.0f * (cr.center.f - l.m*l.c + l.m*cr.center.s);
c = pow(cr.center.f, 2) + pow(cr.center.s, 2) + pow(l.c, 2) - l.c * cr.center.s - pow(cr.radius, 2);
double disc = pow(b, 2) - 4 * a * c;
double x1 = 1.0f * (b + sqrt(disc)) / (2 * a);
double x2 = 1.0f * (b - sqrt(disc)) / (2 * a);
p1 = point(x1, l.getYCorrespoindingTo(x1));
p2 = point(x2, l.getYCorrespoindingTo(x2));
}
double dist(point p11, point p22) {
return sqrt(pow(p11.f-p22.f, 2) + pow(p11.s-p22.s, 2));
}
void print(point x) {
cout << "[" << x.f << ", " << x.s << "]\n";
}
point getCenter(point p_) {
print(point((p_.f+p2.f) / 2, (p_.s+p2.s) / 2));
print(point((p_.f+p1.f) / 2, (p_.s+p1.s) / 2));
if (dist(p_, p1)+eps < dist(p_, p2)) {
return point((p_.f+p2.f) / 2, (p_.s+p2.s) / 2);
}
return point((p_.f+p1.f) / 2, (p_.s+p1.s) / 2);
}
};
int main() {
cin >> R >> x1 >> Y1 >> x2 >> y2;
auto dist = [&]()->double {
return 1.0f * sqrt(pow(x1-x2, 2)+pow(Y1-y2, 2));
};
cout.precision(20);
if(dist() < eps) {
cout << (x1 + R/2) << " " << Y1 << " " << R/2 << "\n";
}
else if (dist() < R) {
double m = 1.0f * (y2-Y1) / (x2-x1);
double c = Y1 - m*x1;
Line l(m, c);
Circle cr(point(x1, Y1), R);
LineCircleInterSection ds(l, cr);
point p = ds.getCenter(point(x2, y2));
double r = (R + dist()) /2;
cout << p.f << " " << p.s << " " << r << "\n";
} else {
cout << x1 << " " << Y1 << " " << R << "\n";
}
return 0;
}