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
21
22using namespace std;
23const double eps = 1E-8;
24const int dx4[4]={1,0,0,-1};
25const int dy4[4]={0,-1,1,0};
26const int inf = 0x3f3f3f3f;
27int dblcmp(double d) {return d<-eps?-1:d>eps;}
28bool ok(double a,double b,double x,double y)
29{
30
31
32 if (dblcmp(a-x)>0&&dblcmp(b-y)>0) return true;
33 if (dblcmp(a-x)<0) return false;
34 double djx =sqrt(x*x*1.0+y*y*1.0);
35 double ax = asin(a*1.0/djx);
36 double ay = asin(x*1.0/djx);
37 double az = ax-ay;
38 double tmp = cos(az)*y+sin(az)*x;
39 if (dblcmp(tmp-b*1.0)<=0) return true;
40 return false;
41
42}
43int main()
44{
45
46 double a,b,x,y;
47 int T;
48 cin>>T;
49 while (T--)
50 {
51 scanf("%lf%lf%lf%lf",&a,&b,&x,&y);
52 if (a>b) swap(a,b);
53 if (x>y) swap(x,y);
54 if (ok(a,b,x,y))
55 puts("Escape is possible.");
56 else puts("Box cannot be dropped.");
57 }
58
59 #ifndef ONLINE_JUDGE
60 fclose(stdin);
61 #endif
62 return 0;
63}