Advertisement
aropan

Самодельный бильярд

Mar 5th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. int n;
  8. double x, y, w, h, r;
  9. double dx, dy, t;
  10.  
  11. long long div(double a, double b)
  12. {
  13.     return (floor)(a / b);
  14. }
  15.  
  16. double mod(double a, double b)
  17. {
  18.     return a - div(a, b) * b;
  19. }
  20.  
  21. int main()
  22. {
  23. /*
  24.     freopen("in", "r", stdin);
  25.     freopen("out", "w", stdout);
  26. //*/
  27.     scanf("%lf %lf %lf %d %lf %lf", &w, &h, &r, &n, &x, &y);
  28.     w -= 2 * r;
  29.     h -= 2 * r;
  30.     x -= r;
  31.     y -= r;
  32.    
  33.     for (int i = 0; i < n; i++)
  34.     {
  35.         scanf("%lf %lf %lf", &dx, &dy, &t);
  36.         dx *= t;
  37.         dy *= t;
  38.        
  39.         double
  40.             X = x + dx,
  41.             Y = y + dy;
  42.            
  43.         long long
  44.             xans = div(max(x, X), w) - div(min(x, X), w),
  45.             yans = div(max(y, Y), h) - div(min(y, Y), h);
  46.         printf("%lld\n", xans + yans);
  47.            
  48.         x = mod(X, w);
  49.         y = mod(Y, h);
  50.         if (xans & 1) x = w - x;
  51.         if (yans & 1) y = h - y;
  52.     }
  53.     return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement