POJ 1380 Equipment Box (determines whether a rectangle can contain another rectangle)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.