【题目描述】
The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events take place at three round stadiums, and the commentator’s objective is to choose the best point of observation, that is to say the point from where all the three stadiums can be observed. As all the sport competitions are of the same importance, the stadiums should be observed at the same angle. If the number of points meeting the conditions is more than one, the point with the maximum angle of observation is prefered.
Would you, please, help the famous Berland commentator G. Berniev to find the best point of observation. It should be noted, that the stadiums do not hide each other, the commentator can easily see one stadium through the other.
【输入】
The input data consists of three lines, each of them describes the position of one stadium. The lines have the format x, y, r, where (x, y) are the coordinates of the stadium’s center ( - 103 ≤ x, y ≤ 103), and r (1 ≤ r ≤ 103) is its radius. All the numbers in the input data are integer, stadiums do not have common points, and their centers are not on the same line.
【输出】
Print the coordinates of the required point with five digits after the decimal point. If there is no answer meeting the conditions, the program shouldn’t print anything. The output data should be left blank.
【样例输入】
0 0 10
60 0 10
30 30 10
【样例输出】
30.00000 0.00000
题目链接:https://codeforces.com/contest/2/problem/C
翻了翻别人AC的代码,清一色的做法都是模拟退火,那就这样吧。。。
十年前tourist在这道题上WA了6次没过( ̄▽ ̄)"
代码如下:
#include <bits/stdc++.h>
using namespace std;
static const double EPS=1e-6;
static const int dx[]={1,-1,0,0};
static const int dy[]={0,0,1,-1};
struct Node{
double x,y,r;
}c[4],p0;
double dis(Node a,Node b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
double check(Node p)
{
double ret=0;
for(int i=1;i<=3;i++)
ret+=(dis(p,c[i])/c[i].r-dis(p,c[(i+1)%3+1])/c[(i+1)%3+1].r)*(dis(p,c[i])/c[i].r-dis(p,c[(i+1)%3+1])/c[(i+1)%3+1].r);
return ret;
}
int main()
{
for(int i=1;i<=3;i++)
{
cin>>c[i].x>>c[i].y>>c[i].r;
p0.x+=c[i].x/3,p0.y+=c[i].y/3;
}
double s=1;
while(s>EPS)
{
bool flag=true;
for(int i=0;i<4;i++)
if(check(Node{p0.x+dx[i]*s,p0.y+dy[i]*s})<check(p0))
{
p0.x+=dx[i]*s;
p0.y+=dy[i]*s;
flag=false;
}
if(flag) s/=2;
}
if(check(p0)<EPS)
cout<<fixed<<setprecision(5)<<p0.x<<" "<<p0.y<<endl;
return 0;
}