HDU 1110 Equipment Box (判斷一個大矩形裏面能不能放小矩形)
阿新 • • 發佈:2018-07-18
分享圖片 accept code esp eal nsis free 傳送門 otto
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
傳送門:
http://acm.hdu.edu.cn/showproblem.php?pid=1110
Equipment Box
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2989 Accepted Submission(s): 759
Sample Output Escape is possible. Box cannot be dropped.
Source Central Europe 1999 分析: 題目意思: 問你一個大矩形裏面能不能放一個小矩形 思路: 1.大矩形長邊大於小矩形長邊並且大矩形短邊大於小矩形短邊 肯定可以放進 2.小矩形面積大於大矩形或者小矩形最短邊大於大矩形最短邊 肯定放不下 3.畫圖。。。(圖片拖起來看,文本格式問題。。。。。。。。。)
code:
#include<bits/stdc++.h> using namespace std; typedef long long LL; #define max_v 25 bool f(double A,double B,double a,double b) { double d=sqrt(a*a+b*b); double a1=asin(A/d); double a2=asin(b/d)*2.0; double h=cos(a1-a2)*d; if(B>h) return true; else return false; } int main() { int t; bool flag; scanf("%d",&t); while(t--) { double A,B,a,b; scanf("%lf %lf %lf %lf",&A,&B,&a,&b); if(A<B) swap(A,B); if(a<b) swap(a,b); if(A>a&&B>b)//大矩形長邊大於小矩形長邊並且大矩形短邊大於小矩形短邊 肯定可以放進 { flag=true; } else if(A*B<=a*b||b>=B)//小矩形面積大於大矩形或者小矩形最短邊大於大矩形最短邊 肯定放不下 { flag=false; }else { flag=f(A,B,a,b); } if(flag) { cout << "Escape is possible." << endl; }else { cout << "Box cannot be dropped." << endl; } } return 0; }
HDU 1110 Equipment Box (判斷一個大矩形裏面能不能放小矩形)