gym101522H(求两个圆相交的区域的任一点)

借鉴了一位大佬的博客:https://www.cnblogs.com/qq936584671/p/8000575.html

题目:

“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 x, y 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.

Example

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.

题意分析:
其实题目对于精度没有很高的要求,求出圆心连线与两个圆的交点,再输出这两个点的中点就能满足精度要求,但这题有个坑点,如果连线不与圆相交就会出错,需要特判。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
const int MAXN=1e5+10;
const double eps=1e-6;
#define INF 0x7fffffff
#define ll long long
#define edl putchar('\n')
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define ROF(i,a,b) for(int i=a;i>=b;i--)
#define mst(a) memset(a,0,sizeof(a))
#define mstn(a,n) memset(a,n,sizeof(a))
struct point
{
    double x,y;
    point() {}
    point(double _a,double _b)
    {
        x=_a;
        y=_b;
    }
};

double distan(point p1,point p2)
{
    return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}


int main()
{
    point a,b,c,d,e;
    double r1,r2,l,s;
    cin>>a.x>>a.y>>r1>>b.x>>b.y>>r2;
    l=distan(a,b);
    if(l<r1||l<r2)
    {
        if(l<r1)
        cout<<b.x<<" "<<b.y<<endl;
        else if(l<r2)
        cout<<a.x<<" "<<a.y<<endl;
    }
    else
    {
        s=l-r2;
        c.x=a.x*l-(a.x-b.x)*s;
        c.y=a.y*l-(a.y-b.y)*s;
        s=l-r1;
        d.x=b.x*l-(b.x-a.x)*s;
        d.y=b.y*l-(b.y-a.y)*s;
        e.x=(c.x+d.x)/2/l;
        e.y=(c.y+d.y)/2/l;

        cout<<e.x<<" "<<e.y<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值