solution
找点一个点使得,该点与三个圆的切线夹角都相等。找点问题,用模拟退火.
让每个
α
\alpha
α (6个) 都相等即找到D点.
code
/*SiberianSquirrel*//*CuteKiloFish*/
#include <bits/stdc++.h>
//#include<bits/extc++.h>
#include<ext/rope>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
#define Inv(x) quick_pow(x, mod - 2)
#define Polynomial vector<int>
#define DEBUG(x, y) cout << x << ": " << y << '\n';
#define mem(a, x) memset(a, x, sizeof a)
#define right_1_pos(x) __builtin_ffs(x)
#define left_0_num(x) __builtin_clz(x)
#define right_0_num(x) __builtin_ctz(x)
#define num_of_1(x) __builtin_popcount(x)
#define Pii pair<int, int>
#define mp_(x, y) make_pair(x, y)
#define all(v) (v).begin(), (v).end()
using ld = long double;
using ll = long long;
//using ill = __int128;
using ull = unsigned long long;
using i16 = short;
const ld pi = acos(-1.0);
const ld eps = 1e-5;
const ll mod = 998244353, mod_g = 3, img = 86583718;
int inv2, inv3;
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> tr;
/*
rb_tree_tag 和 splay_tree_tag 选择树的类型(红黑树和伸展树)
null_type//无映射(g++为null_mapped_type)
less<pii>//从小到大排序
tree_order_statistics_node_update//更新方式
tr.insert(mp_(x, y));//插入
tr.erase(mp_(x, y));//删除
tr.order_of_key(pii(x, y));//求排名
tr.find_by_order(x);//找k小值,返回迭代器
tr.join(b);//将b并入tr,前提是两棵树类型一致并且二没有重复元素
tr.split(v, b);//分裂,key小于等于v的元素属于tr,其余属于b
tr.lower_bound(x);//返回第一个大于等于x的元素的迭代器
tr.upper_bound(x);//返回第一个大于x的元素的迭代器
以上的所有操作的时间复杂度均为O(logn)
注意,插入的元素会去重,如set
*/
//-----------------------------------------------------------------IO Template
namespace StandardIO {
template<typename T> inline void read(T &x) {
x = 0; T f = 1;
char c = getchar();
for (; c < '0' || c > '9'; c = getchar()) if (c == '-') f = -1;
for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0';
x *= f;
}
template<typename T> inline void write(T x) {
if (x < 0) putchar('-'), x *= -1;
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
}
using namespace StandardIO;
// -------------------------------------------------------------------------------BASIC_MATH
namespace BASIC_MATH {
ll mul(ll a, ll b) { ll z = (long double) a / mod * b; ll res = (unsigned long long) a * b - (unsigned long long) z * mod; return (res + mod) % mod; }
// O(1) quick_mul, use long double
inline ll quick_pow(ll ans, ll p, ll res = 1) {
for(; p; p >>= 1, ans = mul(ans, ans) % mod)
if(p & 1) res = mul(res, ans) % mod;
return res % mod;
}
double gcd(double a,double b) {
if(fabs(b) < eps) return a;
if(fabs(a) < eps) return b;
return gcd(b, fmod(a,b));
}
int gcd(int a, int b) { return __gcd(a, b); }
ll gcd(ll a, ll b) { return __gcd(a, b); }
}
using namespace BASIC_MATH;
int sgn(double x) {
if(fabs(x) < eps)return 0;
if(x < 0)return -1;
else return 1;
}
struct Point {
double x,y;
Point() {}
Point(double _x,double _y) {
x = _x;
y = _y;
}
void input() {
cin >> x >> y;
}
void output() {
cout << fixed << setprecision(10) << x << ' ' << y << '\n';
}
bool operator == (Point b)const {
return sgn(x-b.x) == 0 && sgn(y-b.y) == 0;
}
bool operator < (Point b)const {
return sgn(x-b.x)== 0?sgn(y-b.y)<0:x<b.x;
}
Point operator -(const Point &b)const {
return Point(x-b.x,y-b.y);
}
double operator ^(const Point &b)const {//叉积
return x*b.y - y*b.x;
}
double operator *(const Point &b)const {//点积
return x*b.x + y*b.y;
}
double distance(Point p) { //返回两点的距离
return hypot(x-p.x,y-p.y);
}
Point operator +(const Point &b)const {
return Point(x+b.x,y+b.y);
}
Point operator *(const double &k)const {
return Point(x*k,y*k);
}
Point operator /(const double &k)const {
return Point(x/k,y/k);
}
};
struct circle {
Point p; double r;
circle() {}
circle(Point _p,double _r) {
p = _p;
r = _r;
}
circle(double x,double y,double _r) {
p = Point(x,y);
r = _r;
}
void input() { p.input(); cin >> r; }
};
circle c[4];
Point p;
double dx[4]={0, 1, 0, -1},
dy[4]={1, 0, -1, 0};
double calc(Point a) {
double dif = 0, d[3];
for(int i = 0; i < 3; ++ i)
d[i] = a.distance(c[i].p) / c[i].r;
for(int i = 0; i < 3; ++ i)
for(int j = i + 1; j < 3; ++ j)
dif += (d[i] - d[j]) * (d[i] - d[j]);
return dif;
}
void solve() {
double dis = 1.0, now, t;
for(int i = 0; i < 3; ++ i) {
c[i].input();
p = p + c[i].p;
}
p = p / 3.0;
while(dis > eps) {
now = calc(p);
int best = -1;
for(int i = 0; i < 4; ++ i) {
t = calc(p + Point(dis * dx[i], dis * dy[i]));
if(now > t) {
now = t;
best = i;
}
}
if(best == -1) dis = 0.7 * dis;
else p = p + Point(dis * dx[best], dis * dy[best]);
}
if(calc(p) < eps) p.output();
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful!" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
return 0;
}