Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. #include <ctime>
  2. #include <iostream>
  3. typedef float pnt[3];
  4. void count(pnt* pnts, const int n, unsigned cnt[8]) {
  5. for (int i = 0; i < 8; ++i)
  6. cnt[i] = 0;
  7. for (int i = 0; i < n; ++i) {
  8. int index = 0;
  9. int x = -((int)pnts[i][0]) & (1 << 31);
  10. x = abs(x >> 31);
  11. index += x;
  12. int y = -((int)pnts[i][1]) & (1 << 31);
  13. y = abs(y >> 31);
  14. index += (y * 2);
  15. int z = -((int)pnts[i][2]) & (1 << 31);
  16. z = abs(z >> 31);
  17. index += (z * 4);
  18. ++cnt[index];
  19.  
  20.  
  21. }
  22. for (int i = 0; i < 8; ++i)
  23. std::cout << cnt[i] << std::endl;
  24.  
  25. }
  26.  
  27. void counting(pnt* pnts, const int n, unsigned cnt[8]) {
  28. for (int i = 0; i < 8; ++i)
  29. cnt[i] = 0;
  30. for (int i = 0; i < n; ++i) {
  31. if (pnts[i][0] >= 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] >= 0.0f) ++cnt[7]; else
  32. if (pnts[i][0] >= 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] < 0.0f) ++cnt[3]; else
  33. if (pnts[i][0] >= 0.0f && pnts[i][1] < 0.0f && pnts[i][2] >= 0.0f) ++cnt[5]; else
  34. if (pnts[i][0] >= 0.0f && pnts[i][1] < 0.0f && pnts[i][2] < 0.0f) ++cnt[1]; else
  35. if (pnts[i][0] < 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] >= 0.0f) ++cnt[6]; else
  36. if (pnts[i][0] < 0.0f && pnts[i][1] >= 0.0f && pnts[i][2] < 0.0f) ++cnt[2]; else
  37. if (pnts[i][0] < 0.0f && pnts[i][1] < 0.0f && pnts[i][2] >= 0.0f) ++cnt[4]; else
  38. ++cnt[0];
  39.  
  40. }
  41. for (int i = 0; i < 8; ++i)
  42. std::cout << cnt[i] << std::endl;
  43. }
  44. int main() {
  45. srand((unsigned)time(0));
  46. pnt* points = new pnt[16777216];
  47. for (int i = 0; i < 16777216; i++) {
  48. points[i][0] = (-100 +(float)rand() / (float)(RAND_MAX / (100 - -100)));
  49. points[i][1] = (-100 + (float)rand() / (float)(RAND_MAX / (100 - -100)));
  50. points[i][2] = (-100 + (float)rand() / (float)(RAND_MAX / (100 - -100)));
  51. }
  52. unsigned int y[8];
  53. count(points, 16777216, y);
  54. delete [] points;
  55. std::cout << clock();
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement