admin管理员组

文章数量:1565799

HDOJ 1110 Equipment Box

题目

点此查看 HDOJ 1110 Equipment Box

分类

几何
本文配图为我画 没有几何画板 PS也没装 见谅

题意

给两个矩形 判断是否一个能放到另一个内(相等不算)

题解

首先对于 长和宽都大或都小的直接对应
我们看 小长方形的长 大于 大长方形 宽 小于 大长方形 的(要斜着放的)
我们这样处理问题
让小矩形对左上右下点 放在大矩形 上下边 坐下点放在 大矩形左边如图

问题转化成最粗线的长度 即 对角线 乘以 cos 4
用数字表角 djx表示小矩形的对角线
djx×cos4
问题变成求 角 4
7 = c2 / djx
1 = r1 / djx
6 = π/2 -7
4 = 6 - 5
4 = π/2 -7 - 5
由于 1 = 2 3 = π/2 - 7
所以 5 = π - 2 - 3 = π - 1 - ( π/2 - 7) = π/2 - 1 + 7
4 = 6 - 5 = π/2 -7 - 5 = 1 - 2 * 7
至此 4 的公式得出

代码

#include <iostream>
#include <cmath>

using namespace std;

bool jdg(double r1,double c1,double r2,double c2);

int main()
{
    double t,r1,r2,c1,c2;
    bool f;
    cin >> t;
    while(t--)
    {
        cin >> r1 >> c1 >> r2 >> c2;
        if(r1 < c1)
            swap(r1,c1);
        if(r2 < c2)
            swap(r2,c2);
        if(r1 > r2 && c1 > c2)
            f = true;
        else if(r1 * c1 <= r2 * c2 || c2 >= c1)
            f = false;
        else{
            f = jdg(r1,c1,r2,c2);
        }
        if(f)
            cout << "Escape is possible." << endl;
        else
            cout << "Box cannot be dropped." << endl;
    }
    return 0;
}

double dist(double r,double c)
{
    return sqrt(r*r + c*c);
}

bool jdg(double r1,double c1,double r2,double c2)
{
    double djx = dist(r2,c2);
    double a1 = asin(r1 / djx);
    double a2 = asin(c2 / djx) * 2;
    double wd = cos(a1 - a2) * djx;
    if(c1 > wd)
        return true;
    else return false;    
}

本文标签: hduHDOJBoxequipment