Equipment Box
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1171 Accepted Submission(s): 284
Problem Description
There is a large room in the Pyramid called Room-of-No-Return. Its floor is covered by rectangular tiles of equal size. The name of the room was chosen because of the very high number of traps and mechanisms in it. The ACM group has spent several years studying the secret plan of this room. It has made a clever plan to avoid all the traps. A specially trained mechanic was sent to deactivate the most feared trap called Shattered Bones. After deactivating the trap the mechanic had to escape from the room. It is very important to step on the center of the tiles only; he must not touch the edges. One wrong step and a large rock falls from the ceiling squashing the mechanic like a pancake. After deactivating the trap, he realized a horrible thing: the ACM plan did not take his equipment box into consideration. The box must be laid onto the ground because the mechanic must have both hands free to prevent contact with other traps. But when the box is laid on the ground, it could touch the line separating the tiles. And this is the main problem you are to solve.
Input
The input consists of T test cases. The number of them (T) is given on the first line of the input. Each test case consists of a single line. The line contains exactly four integer numbers separated by spaces: A, B, X and Y. A and Bindicate the dimensions of the tiles, X and Y are the dimensions of the equipment box (1 <= A, B, X, Y <= 50000).
Output
Your task is to determine whether it is possible to put the box on a single tile -- that is, if the whole box fits on a single tile without touching its border. If so, you are to print one line with the sentence "Escape is possible.". Otherwise print the sentence "Box cannot be dropped.".
Sample Input
2 10 10 8 8 8 8 10 10
Sample Output
Escape is possible. Box cannot be dropped.
Source
这个题目对于我来说最大的问题是审题的问题,看不懂题目的孩子伤不起啊!!!我们比较的时候a>x&&b>y肯定是没问题的啊,其他的面积都小的没戏,一个宽比另一个宽小的没戏,看图就知道了,我们还需要比较斜放的时候情况,其实核心就是在于对于h和a的大小,看图就知道了,通过角来求,就可以轻松得出。
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int test(double a,double b,double x,double y)
{
if(a*b<x*y)
return 0;
if(a>x&&b>y)
return 1;
if(b<=y)
return 0;
double d=sqrt(x*x+y*y);
double angle=acos(y/d)-acos(b/d);
double h=x*cos(angle)+y*sin(angle);
if(h>a)
return 0;
else
return 1;
}
int main()
{
int i,j;
double a,b,x,y;
int t;
scanf("%d",&t);
while(t--)
{
cin>>a>>b>>x>>y;
if(a<b)
swap(a,b);
if(x<y)
swap(x,y);
if(test(a,b,x,y))
printf("Escape is possible.\n");
else
printf("Box cannot be dropped.\n");
}
return 0;
}