Gym

H. Hit!
time limit per test
1.0 s
memory limit per test
256 MB
input
standard input
output
standard output

"Hit!" is a popular game in ancient Byteland.

The very first version of the game is quite simple: each player picks up a stone and throws it at a circle drawn on the ground. A player wins if his/her stone lands inside the circle.

After 20 years of practice, Bitman, a young man living in ancient Byteland, has mastered the skill of throwing stones – he can throw a stone at any specific place he wants. With such skill, Bitman plays "Hit!" without losing a single game. He simply targets every stone at the center of the circle!

The King of Hackerland hears the story of Bitman and wants to challenge him with a harder, though still very simple, version of "Hit!".

In each game, two circles which share a positive common area are drawn on the ground. In order to win, the player must throw a stone at the common area of the two circles.

As Bitman had no idea how to target his stone at the common area, he asks for your help. Given the coordinates of the centers and radii of the two circles, please tell Bitman the coordinates of any point he can target at such that he can win the game.

For simplicity, you can consider the landing position of the stone as a single point.

Input

The input consists of two lines, each describes one circle drawn on the ground. Each line contains three integers xy and r, denoting respectively the x-coordinate, y-coordinate, and the radius of a circle.

All coordinates have their absolute value no more than 100, and 1 ≤ r ≤ 100 for both circles.

Output

Output two numbers, the x-coordinate and y-coordinate of a point where Bitman can throw his stone at to win the game.

Your answer will be accepted if for each of the two circles, the point lies inside the circle or that the distance between the point and the circle is not greater than 10 - 5.

Examples
input
0 0 3
3 4 3
output
1.5 2.5
input
-7 -9 3
-4 -4 5
output
-6 -7
Note

In the first sample, (1.5, 2.5) is a possible answer as it lies inside the common area of two circles drawn. Please note that there exists more than one possible answer in this case. For example, (2, 2), (1, 2) and (2.1, 1.87) are also possible answers.

 思路:

水题,特判下两个圆的直径大于两圆心距离的情况,这时只要输出圆心就好了。还以为会卡精度,敲了半天,结果告诉队友特判,队友一顿乱敲没考虑精度直接过了。。mmp.

实现代码:

#include<bits/stdc++.h>
using namespace std;

int main()
{
    double x1,x2,y1,y2,z1,z2;
    cin>>x1>>y1>>z1;
    cin>>x2>>y2>>z2;
    double len = pow((x2 - x1),2) + pow((y2 - y1),2);
    len = sqrt(len);
    //cout<<"len :"<<len<<endl;
    double len1 = len - z1;
    double len2 = len - z2;
    //cout<<len1<<" "<<len2<<endl;
    if(len1<=0){
        cout<<x2<<" "<<y2<<endl;
        return 0;
    }
    else if(len2<=0){
        cout<<x1<<" "<<y1<<endl;
        return 0;
    }
    double f1 = x2-x1;
    double f2 = y2-y1;
    double k = len2/len;
    //cout<<k<<endl;
    f1 *= k;
    f2 *= k;
    //printf("%.6lf
",len2);
    double ans;
    while(1){
        ans = pow(f1,2)+pow(f2,2);
        ans = sqrt(ans);
        //printf("%.6lf
",ans);
        if(abs(ans - len2)<0.00001)
            break;
        else{
            if(ans-len2<0.00001){
            f1+=0.000001;f2+=0.000001;}
            else if(ans-len2>0.00001){
            f1-=0.000001;f2-=0.000001;}
        }
    }
    printf("%.6lf %.6lf",x1+f1,y1+f2);
    //cout<<pow((x1+f1),2)+pow((y1+f2),2)<<endl;
}
原文地址:https://www.cnblogs.com/kls123/p/8000774.html