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?
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
Problem Author: Sofia Tekhazheva
Problem Source: Ural Regional School Programming Contest 2010 |
一道集合题吧,关键在于转化为一个直角三角形后,利用勾股定理比较判断能否装进;
#include<iostream>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue>
#include<iomanip>
#include<map>
#include<set>
#define pi 3.14159265358979323846
using namespace std;
int main()
{
double a,b,d,h,r1,r2,r3,r4;
scanf("%lf %lf %lf",&a,&b,&d);
scanf("%lf %lf",&r1,&r2);
scanf("%lf %lf",&r3,&r4);
scanf("%lf",&h);
if(a<b)
swap(a,b);
if(h<=d)
{
r1=r2;
r3=r4;
}
else
{
r1+=(r2-r1)/h*d;
r3+=(r4-r3)/h*d;
}
if(2*r1>b||2*r3>b)
{
printf("NO\n");
}
else
{
double x=a-r1-r3;
double y=b-r1-r3;
if(x*x+y*y>=(r2+r4)*(r2+r4))
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}