欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

问题 B: 【计算几何】Two Circles and a Rectangle

程序员文章站 2022-03-02 10:49:48
...

总在不经意的年生,回首彼岸,纵然发现光景绵长。

题目描述

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.

 

输入

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.

 

输出

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.

 

样例输入

复制样例数据

5 4 1 1
5 4 1.5 2

样例输出

Yes
No

题意就是给你一个矩形还有两个圆,问是否这两个圆能否放在矩形里。

#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#define inf 1000000007
using namespace std;
typedef long long ll;
int pd(double a,double b,double r1,double r2)
{
    double x1,x2,x3;
    x1=min(a,b);
    x2=max(r1,r2);
    if (x1+0.01<x2*2)
        return 0;
    double x=a-r1-r2,y=b-r1-r2,z=r1+r2;
    if(x*x+y*y>=z*z+0.01)
        return 1;
    return 0;
}
int main()
{
    double a,b,r1,r2;
    while(~scanf("%lf%lf%lf%lf",&a,&b,&r1,&r2))
        if (pd(a,b,r1,r2))
            printf("Yes\n");
        else
            printf("No\n");
}