数学一本通——Two Circles and a Rectangle(临界条件)

E. Two Circles and a Rectangle

Description
Give you two circles and a rectangle, your task is to judge whether the two circles can be put into the rectangle with no part of circles outside the retangle.

Input
There are multiple test cases. In every test cast, there are four float-point numbers:
a,b,r1,r2
where, a and b are two sides of the rectangle, r1 and r2 are radii of the two circles.

Output
Print a “Yes”, if the circles can be put into the rectangle. Otherwise, print a “No”.

You can safely assume x<y, where x and y are float-point numbers, if x<y+0.01.

Samples
Input Copy

5 4 1 1
5 4 1.5 2
Output
Yes
No

题意:
给一个矩形和两个圆,问矩形是否能够放开两个圆。
思路:
假设矩形的长为a,宽为b,大圆半径为r1,小圆半径为r2。
首先要满足的条件为b>2*r1。
再来考虑边界情况:
在这里插入图片描述
图片来源
可以看出直角三角形是满足条件的边界条件。
最后,其实不判0.01的精度的能过,就是直接cin没识别多组输入.
代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>PLL;
typedef pair<int,int>PII;
typedef pair<double,double>PDD;
#define I_int ll
inline ll read()
{
    
    
    ll x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
    
    
        if(ch=='-')f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
    
    
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a,ll b,ll p)
{
    
    
    ll res=1;
    while(b)
    {
    
    
        if(b&1)res=res*a%p;
        a=a*a%p;
        b>>=1;
    }
    return res;
}
#define PI acos(-1)
#define x first
#define y second

int main(){
    
    
    double a,b,r1,r2;
    while(scanf("%lf%lf%lf%lf",&a,&b,&r1,&r2)!=EOF){
    
    
        if(a<b) swap(a,b);///a为长边
        if(r1<r2) swap(r1,r2);///r1为大圆半径
        if(b<2*r1) puts("No");
        else{
    
    
            if((r1+r2)*(r1+r2)<=(a-r1-r2)*(a-r1-r2)+(b-r1-r2)*(b-r1-r2)) puts("Yes");
            else puts("No");
        }
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_45675097/article/details/114339618