ZOJ 1608 Two Circles and a Rectangle

Give you two circles and a rectangle, your task is to judge wheather 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 circls.


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.


Sample Input

5 4 1 1
5 4 1.5 2


Sample Output

Yes
No

//数学一本通习题 1
//ZOJ 1608 判断两个圆能否放入一个矩形中

//题意:给你一个矩形和两个圆,问能否把这两个圆放进矩形里(圆不能相交或包含) 

//最好(省空间)的放置方法显然是两个圆分别与两条对边相切,且这两个圆也相切
//假如两个圆是按上面的方法放的,且刚好能放下(即两组邻边分别与两个圆相切) 
//那么假设两个圆圆心的距离是z
//以z为斜边,x平行于长,y平行于宽做直角三角形 ,则
//z=r1+r2 
//x=a-r1-r2=a-z
//y=b-r1-r2=b-z
//所以,z是固定的,x和y取决于矩形的边长
//那么如果x^2+y^2==z^2的话,就是刚好能放下,>=就是能放下了 

#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

const int N=1e5+5;

double a,b,r1,r2;
double x,y,z;

int main()
{
    while(scanf("%lf%lf%lf%lf",&a,&b,&r1,&r2)!=EOF)
    {
        z=r1+r2;
        if(a<b)        //让a是长边,b是短边 
            swap(a,b);
        if(r1<r2)    //r1是大圆,r2是小圆 
            swap(r1,r2);
        x=a-z,y=b-z;
        if(x*x+y*y>=z*z)
            puts("Yes");
        else
            puts("No");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/lovewhy/p/8978602.html