题意:在平面上找一个点,使它对三个圆的视角相等.
从中心开始进行爬山算法,
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
using namespace std;
const double eps = 1e-6;
const double inf = 1e20;
struct Node
{
double x, y;
}node[3];
double cha[3], r[3];
double p2(double x)
{
return x * x;
}
double check(double x, double y)
{
double res = 0;
for (int i = 0; i < 3; i++)
{
cha[i] = sqrt(p2(x - node[i].x) + p2(y - node[i].y)) / r[i];
}
for (int i = 0; i < 3; i++)
{
res += p2(cha[i] - cha[(i + 1) % 3]);
}
return res;
}
void input()
{
double a = 0, b = 0;
int t = 0;
while (scanf("%lf %lf %lf", &node[t].x, &node[t].y, &r[t]) != EOF)
{
a += node[t].x, b += node[t].y;
t++;
if (t == 3)
{
a /= 3, b /= 3;
bool flag = false;
double temp = check(a, b);
for (double s = 1.0; s >= eps; flag = false)
{
if (temp > check(a + s, b))
{
temp = check(a + s, b);
a += s;
flag = true;
}
else if (temp > check(a - s, b))
{
temp = check(a - s, b);
a -= s;
flag = true;
}
else if (temp > check(a, b + s))
{
temp = check(a, b + s);
b += s;
flag = true;
}
else if (temp > check(a, b - s))
{
temp = check(a, b - s);
b -= s;
flag = true;
}
//cout << temp << endl;
if (!flag) s *= 0.7;
}
if (temp < eps)
{
printf("%.6lf %.6lf\n", a, b);
}
}
}
}
int main()
{
input();
return 0;
}