Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <complex>
- #include <stdio.h>
- #include <cmath>
- const double PI = 4 * atan(1.0);
- const double step = 0.0000008;
- const int count = (int)(PI / 2 / step) + 1;
- const double EPS = 0.000008;
- struct Square {
- std::complex<double> A, B, C, D;
- Square (int w = 0, int h = 0)
- : A (-0.5*w, -0.5*h)
- , B (-0.5*w, 0.5*h)
- , C (0.5*w, 0.5*h)
- , D (0.5*w, -0.5*h)
- { }
- void mul(const std::complex<double> & rotate_factor) {
- A *= rotate_factor;
- B *= rotate_factor;
- C *= rotate_factor;
- D *= rotate_factor;
- }
- double right() const {
- return std::max(std::max(A.real(), B.real()), std::max(C.real(), D.real()));
- }
- double left() const {
- return std::min(std::min(A.real(), B.real()), std::min(C.real(), D.real()));
- }
- double top() const {
- return std::max(std::max(A.imag(), B.imag()), std::max(C.imag(), D.imag()));
- }
- double bottom() const {
- return std::min(std::min(A.imag(), B.imag()), std::min(C.imag(), D.imag()));
- }
- double box_width() const {
- return right() - left();
- }
- double box_height() const {
- return top() - bottom();
- }
- bool canPlace(int Width, int Height) const {
- return box_height() - Height <= EPS && box_width() - Width <= EPS;
- }
- };
- int main() {
- freopen("input.txt", "rt", stdin);
- int w, h;
- scanf("%d %d", &w, &h);
- if (w < h) std::swap(w, h);
- Square sq(w, h);
- int W, H;
- scanf("%d %d", &W, &H);
- if (W < H) std::swap(W, H);
- std::complex<double> rotate_factor = std::polar(1.0, step);
- for (int i = 0; i < count && !sq.canPlace(W, H); ++i)
- sq.mul(rotate_factor);
- printf(sq.canPlace(W, H) ? "Possible" : "Impossible");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement