Advertisement
dmkozyrev

acmp 362.cpp

Jul 4th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #include <iostream>
  2. #include <complex>
  3. #include <stdio.h>
  4. #include <cmath>
  5.    
  6. const double PI = 4 * atan(1.0);
  7. const double step = 0.0000008;
  8. const int count = (int)(PI / 2 / step) + 1;
  9. const double EPS = 0.000008;
  10.    
  11. struct Square {
  12.        
  13.     std::complex<double> A, B, C, D;
  14.        
  15.     Square (int w = 0, int h = 0)
  16.         : A (-0.5*w, -0.5*h)
  17.         , B (-0.5*w, 0.5*h)
  18.         , C (0.5*w, 0.5*h)
  19.         , D (0.5*w, -0.5*h)
  20.     { }
  21.        
  22.     void mul(const std::complex<double> & rotate_factor) {
  23.         A *= rotate_factor;
  24.         B *= rotate_factor;
  25.         C *= rotate_factor;
  26.         D *= rotate_factor;
  27.     }
  28.        
  29.     double right() const {
  30.         return std::max(std::max(A.real(), B.real()), std::max(C.real(), D.real()));
  31.     }
  32.        
  33.     double left() const {
  34.         return std::min(std::min(A.real(), B.real()), std::min(C.real(), D.real()));
  35.     }
  36.        
  37.     double top() const {
  38.         return std::max(std::max(A.imag(), B.imag()), std::max(C.imag(), D.imag()));
  39.     }
  40.        
  41.     double bottom() const {
  42.         return std::min(std::min(A.imag(), B.imag()), std::min(C.imag(), D.imag()));
  43.     }
  44.        
  45.     double box_width() const {
  46.         return right() - left();
  47.     }
  48.        
  49.     double box_height() const {
  50.         return top() - bottom();
  51.     }
  52.        
  53.     bool canPlace(int Width, int Height) const {
  54.         return box_height() - Height <= EPS && box_width() - Width <= EPS;
  55.     }
  56. };
  57.    
  58. int main() {      
  59.     freopen("input.txt", "rt", stdin);
  60.        
  61.     int w, h;
  62.     scanf("%d %d", &w, &h);
  63.        
  64.     if (w < h) std::swap(w, h);
  65.        
  66.     Square sq(w, h);
  67.        
  68.     int W, H;
  69.     scanf("%d %d", &W, &H);
  70.        
  71.     if (W < H) std::swap(W, H);
  72.        
  73.     std::complex<double> rotate_factor = std::polar(1.0, step);
  74.        
  75.     for (int i = 0; i < count && !sq.canPlace(W, H); ++i)
  76.         sq.mul(rotate_factor);
  77.        
  78.     printf(sq.canPlace(W, H) ? "Possible" : "Impossible");
  79.        
  80.        
  81.     return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement