poj 1380 Equipment Box (简单几何)

题目链接

题意:问一个小矩形能否放在一个大矩形中,给定两个矩形的尺寸。

思路:主要是斜着放比较难判断。学弟貌似写了离散化角度旋转。。。我的做法是。。直接考虑对角线。。。因为我认为对角线是最有可能放进去的位置。

 1#include <cstdio>
 2#include <cstring>
 3#include <iostream>
 4#include <algorithm>
 5#include <vector>
 6#include <queue>
 7#include <set>
 8#include <map>
 9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6int dblcmp(double d) {return d<-eps?-1:d>eps;}
7bool ok(double a,double b,double x,double y)
8{
1    if (dblcmp(a-x)>0&&dblcmp(b-y)>0) return true;
2    if (dblcmp(a-x)<0) return false;
3    double djx =sqrt(x*x*1.0+y*y*1.0);
4    double ax = asin(a*1.0/djx);
5    double ay = asin(x*1.0/djx);
6    double az = ax-ay;
7    double tmp = cos(az)*y+sin(az)*x;
8    if (dblcmp(tmp-b*1.0)<=0) return true;
9    return false;
1}
2int main()
3{
 1	double a,b,x,y;
 2	int T;
 3	cin>>T;
 4	while (T--)
 5	{
 6	    scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
 7	    if (a>b) swap(a,b);
 8	    if (x>y) swap(x,y);
 9	    if (ok(a,b,x,y))
10		puts("Escape is possible.");
11	    else puts("Box cannot be dropped.");
12	}
1  #ifndef ONLINE_JUDGE  
2  fclose(stdin);
3  #endif
4    return 0;
5}