Advertisement
Guest User

Untitled

a guest
Sep 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. class Coordinates
  6. {
  7. public:
  8.     Coordinates() {}
  9.     int x;
  10.     int y;
  11.     Coordinates(int x, int y)
  12.     {
  13.         this->x = x;
  14.         this->y = y;
  15.     }
  16. };
  17. class  Hamster :public Coordinates
  18. {
  19. public:
  20.     Hamster(int x, int y):Coordinates(x, y) {}
  21.     float time(Coordinates & b) {
  22.         return (abs(b.x - x) > abs(b.y - y) ? abs(b.y - y) : abs(b.x - x) );
  23.     }
  24. };
  25. class  Dog :public Coordinates
  26. {
  27. public:
  28.     Dog(int x, int y) :Coordinates(x, y) {}
  29.     float time(Coordinates & b) {
  30.         return (abs(b.x - x) > abs(b.y - y) ? abs((b.y - y)/2):abs((b.x - x)/2));
  31.     }
  32. };
  33. class  Den:public Coordinates
  34. {
  35. public:
  36.     Den() {};
  37.     Den(int x, int y) :Coordinates(x, y) {}
  38.     void Print()
  39.     {
  40.         cout << x << " " << y << endl;
  41.     }
  42. };
  43. int main()
  44. {
  45.     int x1, y1, x2, y2, n,x,y,time,k;
  46.     cin >> x1 >> y1 >> x2 >> y2 >> n;
  47.     Hamster FastHamster(x1, y1);
  48.     Dog AgryDog(x2,y2);
  49.     Den min(10000, 10000);
  50.     Den* arr = new Den[n];
  51.     for (int i = 0; i < n; i++)
  52.     {
  53.         cin >> x >> y;
  54.         Den Cave(x, y);
  55.         arr[i] = Cave;
  56.         if (abs(arr[i].x-FastHamster.x)<min.x && abs(arr[i].y-FastHamster.y)<min.y)
  57.         {
  58.             min = arr[i];
  59.             k = i;
  60.         }
  61.     }
  62.     if(FastHamster.time(min) < AgryDog.time(min))
  63.     cout<<k+1;
  64.     else cout<<"NO";
  65.     delete[] arr;
  66.     return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement