計算幾何 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;
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章