The_Law

Untitled

Oct 4th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. double mx(double a, double b)
  5. {
  6.     if (a > b)
  7.         return a;
  8.     return b;
  9. }
  10.  
  11. double mn(double a, double b)
  12. {
  13.     if (a < b)
  14.         return a;
  15.     return b;
  16. }
  17.  
  18. int main(void)
  19. {
  20.     double a, b, c, d;
  21.     scanf("%lf%lf%lf%lf", &a, &b, &c, &d);
  22.  
  23.     double OX, OY;
  24.     OX = (double)(b) / 2;
  25.     OY = (double)(a) / 2;
  26.  
  27.     double d2 = c * c + d * d;
  28.     double r2 = d2 / 4;
  29.  
  30.  
  31.     //Finding cross b
  32.     double D1 = -4 * (a * a - 2 * a * OY + OY * OY - r2);
  33.  
  34.     double sqrtD1;
  35.     for (int i = 0; i * i <= D1; ++i)
  36.         sqrtD1 = i;
  37.  
  38.     double xb1 = (2 * OX + sqrtD1) / 2;
  39.     double xb2 = (2 * OX - sqrtD1) / 2;
  40.  
  41.     //finding cross a
  42.     double D2 = -4 * (OX * OX - r2);
  43.  
  44.     double sqrtD2;
  45.     for (int i = 0; i * i <= D2 * D2; ++i)
  46.         sqrtD2 = i;
  47.  
  48.     double xa1 = (2 * OY + sqrtD2) / 2;
  49.     double xa2 = (2 * OY - sqrtD2) / 2;
  50.  
  51.     if (D1 <= 0 && D2 <= 0)
  52.         printf("YES");
  53.     else
  54.         if (D1 > 0 && D2 > 0)
  55.         {
  56.             double cbm = mn(xb1, xb2);
  57.             if (cbm < 0 || cbm > b)
  58.                 cbm = mx(xb1, xb2);
  59.  
  60.             if (cbm < 0 || cbm > b)
  61.                 printf("NO");
  62.             else
  63.             {
  64.                 double cam = mn(xa1, xa2);
  65.                 if (cam < 0 || cam > a)
  66.                     cam = mx(xa1, xa2);
  67.  
  68.                 if (cam < 0 || cam > a)
  69.                     printf("NO");
  70.                 else
  71.                     if (cam * cam + cbm * cbm >= c)
  72.                         printf("YES");
  73.                     else
  74.                         printf("NO");
  75.             }
  76.         }
  77.         else
  78.             if (D1 > 0 && (0 <= xb1 && xb1 <= b) && (0 <= xb2 && xb2 <= b) && (mx(xb1, xb2) - mn(xb1, xb2) >= d))
  79.                 printf("YES");
  80.             else
  81.                 if (D2 > 0 && (0 <= xa1 && xa1 <= a) && (0 <= xa2 && xa2 <= a) && (mx(xa1, xa2) - mn(xa1, xa2) >= c))
  82.                     printf("YES");
  83.                 else
  84.                     printf("NO");
  85.  
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment