fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3. struct TVector{
  4. int x,y;
  5. };
  6. class Rect
  7. {
  8. int x1, y1, x2, y2;
  9. public:
  10. TVector Speed;
  11. Rect(int ax1, int ay1, int ax2, int ay2) :x1(ax1), y1(ay1), x2(ax2), y2(ay2)
  12. {
  13.  
  14. }
  15. void Move(){*this+=Speed;};
  16. bool Intersect(Rect& R) { return !(x1>R.x2 || x2<R.x1 || y1>R.y2 || y2<R.y1); }
  17. Rect& operator +=(const TVector& r){x1+=r.x;x2+=r.x;y1+=r.y;y2+=r.y; return *this;}
  18. };
  19.  
  20. int main() {
  21.  
  22. int Hit = 0, Miss = 0;
  23. Rect PlayerBox(0, 0, 50, 100);
  24. Rect BulletBox(0,0, 10, 5);
  25. PlayerBox+=TVector{-100000000,0};
  26. BulletBox+=TVector{100000000,20};
  27. PlayerBox.Speed=TVector{1,0};
  28. BulletBox.Speed=TVector{-1,0};
  29. for (int i = 0; i < 100000000; i++) {
  30. PlayerBox.Move();
  31. BulletBox.Move();
  32. PlayerBox.Intersect(BulletBox)?Hit++:Miss++;
  33. }
  34.  
  35.  
  36. cout << "Hits:" << Hit << " Miss:" << Miss << " Total:" << (Hit + Miss);
  37.  
  38. return 0;
  39. }
Success #stdin #stdout 0.05s 16064KB
stdin
Standard input is empty
stdout
Hits:26 Miss:99999974 Total:100000000