Equipment Box
Blog original address: http://blog.csdn.net/xuechelingxiao/article/details/40867049
Question:
Let's show you the length and width of two rectangles and ask if the first rectangle can contain the second rectangle.
Solution:
This question may seem very simple at first glance, but if you look at it carefully, there will be a special situation that is easily overlooked,
This situation is easy to ignore. In this case, you need to extract the red or yellow triangle from the first pair, which is not very difficult to judge. You can take a look at the code and understand it very well.
Code:
# Include <stdio. h> # include <math. h> int main () {double a, B, x, y, L1, L2; int T; scanf ("% d", & T); while (T --) {scanf ("% lf", & a, & B, & x, & y); if (a <B) {double temp =; a = B; B = temp;} if (x <y) {double temp = x; x = y; y = temp ;} if (a> x & B> y) {printf ("Escape is possible. \ n "); continue;} else if (x * x + y * y> a * a + B * B) {printf (" Box cannot be dropped. \ n "); continue;} else {// L1 = (a-sqrt (double) (x * x + y * y-B * B)/2; L2 = (B-sqrt (double) (x * x + y * y-a * a)/2; if (L1 * L1 + L2 * L2> y * y) printf ("Escape is possible. \ n "); else printf (" Box cannot be dropped. \ n ") ;}} return 0 ;}
POJ 1380 Equipment Box (determines whether a rectangle can contain another rectangle)