Advertisement
savrasov

METRO

May 16th, 2017
372
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <cstring>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9. typedef long double ld;
  10.  
  11. int main()
  12. {
  13.     int x0, y0, r, x1, y1, x2, y2, a, b, c, ans = 0;
  14.     ld yy, xx;
  15.     cin >> x0 >> y0 >> r >> x1 >> y1 >> x2 >> y2;
  16.     a = y2 - y1;
  17.     b = -(x2 - x1);
  18.     c = -a * x1 - b * y1;
  19.     if(x1 == x2)
  20.     {
  21.         for(int i = -r; i <= r; i++)
  22.         {
  23.             yy = (-b * (y0 + i) - c) / a;
  24.             if((ll)yy == yy && (yy >= x0 - r && yy <= x0 + r)) ans++;
  25.         }
  26.     }
  27.     else
  28.     {
  29.         for(int i = -r; i <= r; i++)
  30.         {
  31.             xx = (-a * (x0 + i) - c) / b;
  32.             if((ll)xx == xx && (xx >= y0 - r && xx <= y0 + r)) ans++, cout << i << " ";
  33.         }
  34.     }
  35.     cout << ans;
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement