zoj-3806(几何+二分)

问题描述:

A triangle is one the basic shapes in geometry. It's a polygon with three vertices and three sides which are line segments. A triangle with vertices AB, C is denoted ΔABC. And its three sides, BCCAAB are often denoted ab and c.

The incircle of a triangle is the largest circle contained in the triangle, it is tangent to the three sides. The center of the incircle is called the triangle's incenter and the radius of the incircle is called inradius, which is denoted r.

The circumcircle of a triangle is the circle which passes through all its three vertices. The center of the this circle is called circumcenter and its radius is called circumradius, which is denoted R.

It's very easy to calculate r and R after knowing ab and c. Now you are given rand R, can you calculate a valid triple (abc)?

Input

There are multiple cases. Each case has two positive integers r and R in one line. (r and R are less than 105)

Ouput

For each case, print three floating numbers ab and c in one line if it's possible to get r and R. If there are no possible tuples, print "NO Solution!".

The judge program uses your ab and c to calculate the inradius and circumradius. Only the relative error of your inradius and circumradius less than 10-8 will be accepted.

Sample Input
1 2
2 5
9 9
Sample Ouput
3.464101615137754587 3.464101615137754587 3.464101615137754587
6 8 10
NO Solution!

题目题意:题目给我们一个(三角形的)外接圆和一个内接圆的半径,让我们求出一个三角形满足题意,输出三角形三边长.

题目分析:这道题目,当时是没有什么思路的,过后看到这个大佬的博客,才理解了,写出了自己的AC代码.

大佬的链接(讲的很好):点击打开链接

大佬里面讲的很清楚了,我的代码只是在二分时,用了自己的判断方法。

我的思路是通过知道底边mid,然后勾股定理求腰a,求高,我们算出此时这个三角形的面积s

根据等面积法,我们可以得到等式p*r1=s (其中p为三角形的周长的一半),求出每个三角形的内接圆的半径r1,然后和题目的内接圆的半径相比较,来更新范围.


代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

const double epx=1e-10;

double spow(double a)
{
    return a*a;
}
int main()
{
    double R,r;
    while (scanf("%lf%lf",&r,&R)!=EOF) {
        if (R<2*r) {
            printf("NO Solution!\n");
            continue;
        }
        double left=0,right=sqrt(3.0)*R;
        while (right-left>epx) {
            double mid=(right+left)/2.0;
            double a=sqrt(spow(sqrt(spow(R)-spow(mid/2.0))+R)+spow(mid/2.0));
            double s=(sqrt(spow(R)-spow(mid/2.0))+R)*mid/2.0;
            double p=(a+a+mid)/2.0;
            double r1=s/p;
            if (r1-r>epx) right=mid;
            else left=mid;
        }
        double a=sqrt(spow(sqrt(spow(R)-spow(left/2.0))+R)+spow(left/2.0));
        double b=left;
        printf("%.16lf %.16lf %.16lf\n",a,a,b);
    }
    return 0;
}



















1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。 1、资源项目源码均已通过严格测试验证,保证能够正常运行; 2、项目问题、技术讨论,可以给博主私信或留言,博主看到后会第一时间与您进行沟通; 3、本项目比较适合计算机领域相关的毕业设计课题、课程作业等使用,尤其对于人工智能、计算机科学与技术等相关专业,更为适合; 4、下载使用后,可先查看README.md或论文文件(如有),本项目仅用作交流学习参考,请切勿用于商业用途。 5、资源来自互联网采集,如有侵权,私聊博主删除。 6、可私信博主看论文后选择购买源代码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值