CodeForces

来源:互联网 发布:三角洲特种部队mac版 编辑:程序博客网 时间:2024/06/08 04:41

C. Commentator problem
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output

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.

Input

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.

Output

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.

Examples
input
0 0 1060 0 1030 30 10
output
30.00000 0.00000

题意:给你三个圆,找到一个点,使得这个点与三个圆分别构成的视角大小都一样。可以联立方程组求出来,极其复杂恶心...。要我解方程是不可能的。

思路:模拟退火。先确定一个点,求出三个视角的误差值,然后不断更新这个点的坐标,减小误差值,以确定最终答案。

#include <bits/stdc++.h>using namespace std;struct Point{    double x,y,r;}p[10];int d[4][2]={-1,0,0,-1,1,0,0,1};double angle[3];double dis(Point a,Point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}double cla(Point a)  //求误差{    for(int i=0;i<3;i++)angle[i]=dis(a,p[i])/p[i].r;    double err=0;    for(int i=0;i<3;i++)err+=(angle[i]-angle[(i+1)%3])*(angle[i]-angle[(i+1)%3]);    return err;}int main(){    double ansx,ansy;    for(int i=0;i<3;i++)cin>>p[i].x>>p[i].y>>p[i].r;    ansx=(p[0].x+p[1].x+p[2].x)/3;    ansy=(p[0].y+p[1].y+p[2].y)/3;  //初始坐标    double err=cla((Point){ansx,ansy,0});//初始误差    double step=1;    for(int T=1;T<=1e5;T++)   //不断更新点坐标    {        int tag=0;        double x,y;        for(int i=0;i<4;i++)        {            double nx=ansx+d[i][0]*step;            double ny=ansy+d[i][1]*step;            double error=cla((Point){nx,ny,0});            if(error<err)   //误差变小,更新坐标            {                err=error;                x=nx;                y=ny;                tag=1;            }        }        if(tag==0)step/=2;   //减少更新幅度,慢慢逼近        else ansx=x,ansy=y;    }    if(err<1e-6)printf("%0.5lf %0.5lf\n",ansx,ansy);  //答案合理的话就输出    return 0;}




原创粉丝点击