1793. Tray 2
Time Limit: 1.0 second
Memory Limit: 64 MB
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?
Input
The first line contains the integers
a,
b, 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;
}