C - 盒子嵌套
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.
重点是公式:ans = c*cos(acos(d/sqrt(c*c+d*d))-acos(b/sqrt(c*c+d*d)))+d*sin(acos(d/sqrt(c*c+d*d))-acos(b/sqrt(c*c+d*d))) < a;
下面是代码:(公式看不懂的话看代码会好一点,因为公式是真的很长)
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
using namespace std;
int main()
{
int T;
scanf("%d", &T);
while(T--)
{
double A, B, C, D;
double a, b, c, d;
scanf("%lf%lf%lf%lf", &A, &B, &C, &D);
b = min(A, B), a = max(A,B), d = min(C, D), c = max(C, D);
if(c*d>a*b)
printf("Box cannot be dropped.\n");
else if(a>c && b>d)
printf("Escape is possible.\n");
else if(d >= b)
printf("Box cannot be dropped.\n");
else
{
double x = sqrt(c*c+d*d);
double y = acos(d/x)-acos(b/x);
double ans = c*cos(y)+d*sin(y);
if(ans > a)
printf("Box cannot be dropped.\n");
else
printf("Escape is possible.\n");
}
}
}