计算几何 ural 1793Tray 2

1793. Tray 2

Time Limit: 1.0 second
Memory Limit: 64 MB
One of the organizers of the Ural Regional School Programming Contest came to the university cafeteria to have lunch. He took a soup and a main course and tried to arrange them on a small rectangular tray, which was not so easy. “Oops, that's a problem,” he thought. “Oh, yes, that's a problem! A nice problem for the contest!”
The Ural State University's cafeteria has trays with a rectangular  a ×  b bottom and vertical borders of height  d. Plates have the shape of a truncated cone. All the plates in the cafeteria have the same height  h. The organizer wants to put the plates on the tray so that their bottoms adjoin the bottom of the tray completely. Can he do it?
Problem illustration

Input

The first line contains the integers  ab, and  dseparated with a space. Each of the following lines describes one of the plates and contains two integers. The former integer is the radius of the plate's bottom and the latter integer is the radius of the circle formed by the edge of the plate. The second radius is greater than the first one. The last line contains the height  hof the plates. All the input integers are positive and do not exceed 1000.

Output

Output “YES” if the plates can be arranged on the tray and “NO” otherwise.

Samples

input output
10 10 10
1 2
1 2
5
YES
8 4 1
1 2
1 3
1
NO
题意:判断两个盘子是否可以放入托盘中,使得盘子底部与托盘完全相接触。
思路:
1.首先判断两个盘子是否可以放入托盘,即判断两个盘子底部是否可以放入托盘中。
2.然后判断盘子的高度是否大于托盘高度,是的话需要扩充托盘,使得托盘与盘子一般高。(等比缩放)
3.判断两个盘子是否可以完全放入托盘,即判断两个盘子上部是否可以放入托盘中。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;


struct plate {
    double r, R;
};

plate p1, p2;

int main()
{
    double a, b, d, h, r, R, sqr, dr, dh;
    bool flag = true;
    scanf("%lf %lf %lf", &a, &b, &d);
    scanf("%lf %lf", &p1.r, &p1.R);
    scanf("%lf %lf", &p2.r, &p2.R);
    scanf("%lf", &h);
    if (p1.r*2 > a || p1.r > b || p2.r > a || p2.r > b)
        flag = false;
    else {
        r = a - p1.r - p2.r;
        R = b - p1.r - p2.r;
        sqr = sqrt(r*r + R*R);
        if (sqr < p1.r+p2.r)
            flag = false;
        else {
            if (h > d) {
                dr = p1.R - p1.r;
                dh = h - d;
                a += dr*dh/h;
                b += dr*dh/h;
                dr = p2.R - p2.r;
                a += dr*dh/h;
                b += dr*dh/h;
            }
            if (p1.R*2 > a || p1.R > b || p2.R > a || p2.R > b)
                flag = false;
            else {
                r = a - p1.R - p2.R;
                R = b - p1.R - p2.R;
                sqr = sqrt(r*r + R*R);
                if (sqr < p1.R+p2.R)
                    flag = false;
            }
        }
    }
    if (flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值