Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #define N 24
  4.  
  5. int center;
  6. int centerSq;
  7.  
  8. int splits = 1;
  9.  
  10. bool filled(int x, int y) {
  11. return (x-center)*(x-center) + (y-center)*(y-center) <= centerSq;
  12. }
  13.  
  14. void parse_range(int xLow, int xHigh, int yLow, int yHigh) {
  15. bool a,b,c,d;
  16. a = filled(xLow,yLow);
  17. b = filled(xLow,yHigh-1);
  18. c = filled(xHigh-1,yLow);
  19. d = filled(xHigh-1,yHigh-1);
  20.  
  21. if (a && b && c && d || !(a || b || c || d)) {
  22. // printf("We did not need to split: (%d,%d) to (%d,%d)\n",xLow,yLow,xHigh,yHigh);
  23. return;
  24. }
  25.  
  26. // printf("Splitting: (%d,%d) to (%d,%d)\n",xLow,yLow,xHigh,yHigh);
  27. splits++;
  28.  
  29. int xMid = xLow + (xHigh - xLow) / 2;
  30. int yMid = yLow + (yHigh - yLow) / 2;
  31. parse_range(xLow,xMid,yLow,yMid);
  32. parse_range(xLow,xMid,yMid,yHigh);
  33. parse_range(xMid,xHigh,yLow,yMid);
  34. parse_range(xMid,xHigh,yMid,yHigh);
  35.  
  36. }
  37.  
  38. int main() {
  39. center = 1 << (N-1);
  40. centerSq = center * center;
  41.  
  42. parse_range(0,1 << N-1,0,1 << N-1);
  43. parse_range(0,1 << N-1,1 << N-1,1 << N);
  44. parse_range(1 << N-1,1 << N,0,1 << N-1);
  45. parse_range(1 << N-1,1 << N,1 << N-1,1 << N);
  46.  
  47. std::cout << splits;
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement