fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <cmath>
  4. #include <limits>
  5.  
  6. #include <math.h>
  7.  
  8. using namespace std;
  9.  
  10. static bool can_fit(int a, int b, int x, int y)
  11. {
  12. //first make a>=b and x>=y
  13. if(b>a)
  14. {
  15. ::std::swap(a,b);
  16. }
  17. if(y>x)
  18. {
  19. ::std::swap(x,y);
  20. }
  21. if(x<=a)
  22. {
  23. if(y<=b)
  24. {
  25. return true;
  26. }
  27. else
  28. {
  29. return false;
  30. }
  31. }
  32. else
  33. {
  34. if(y<=b)
  35. {
  36. //try rotate
  37. double lb=2*atan((double)y/(double)x);
  38. double ub=M_PI/2-lb;
  39. while(ub-lb> ::std::numeric_limits<double>::epsilon())
  40. {
  41. double alpha=(lb+ub)/2;
  42. double w=(double)x*cos(alpha)+(double)y*sin(alpha);
  43. double h=(double)y*cos(alpha)+(double)x*sin(alpha);
  44. if(w<=a)
  45. {
  46. if(h<=b)
  47. {
  48. return true;
  49. }
  50. else
  51. {
  52. ub=alpha;
  53. }
  54. }
  55. else
  56. {
  57. lb=alpha;
  58. }
  59. //cout<<alpha<<","<<lb<<","<<ub<<endl;
  60. }
  61. return false;
  62. }
  63. else
  64. {
  65. return false;
  66. }
  67. }
  68. }
  69.  
  70.  
  71. int main()
  72. {
  73. int t;
  74. cin>>t;
  75. for(int i=0;i<t;++i)
  76. {
  77. int a,b,x,y;
  78. cin>>a>>b>>x>>y;
  79. if(can_fit(a,b,x,y))
  80. {
  81. cout<<"Escape is possible."<<endl;
  82. }
  83. else
  84. {
  85. cout<<"Box cannot be dropped."<<endl;
  86. }
  87. }
  88. return 0;
  89. }
Success #stdin #stdout 0s 3300KB
stdin
2
10 10 8 8
8 8 10 10
stdout
Escape is possible.
Box cannot be dropped.