fork(5) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Rect
  5. {
  6. int x1, y1, x2, y2;
  7. public:
  8. Rect(int ax1, int ay1, int ax2, int ay2) :x1(ax1), y1(ay1), x2(ax2), y2(ay2)
  9. {
  10.  
  11. }
  12. bool Intersect(Rect& R) { return !(x1>R.x2 || x2<R.x1 || y1>R.y2 || y2<R.y1); }
  13. };
  14.  
  15. int main() {
  16.  
  17. int Hit = 0, Miss = 0;
  18. for (int i = 0; i < 100000000; i++) {
  19. int x1 = rand() % 1001 - 500;
  20. int x2 = rand() % 1001 - 500;
  21. int y1 = rand() % 1001 - 500;
  22. int y2 = rand() % 1001 - 500;
  23. Rect PlayerBox(x1, y1, x1 + 50, y1 + 100);
  24. Rect BulletBox(x2, y2, x2 + 10, y2 + 5);
  25. PlayerBox.Intersect(BulletBox)?Hit++:Miss++;
  26. }
  27.  
  28.  
  29. cout << "Hits:" << Hit << " Miss:" << Miss << " Total:" << (Hit + Miss);
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 2.55s 16064KB
stdin
Standard input is empty
stdout
Hits:600153 Miss:99399847 Total:100000000