inlinedoublegetDis(int x, int y) { returnsqrt(x*x + y*y); } intmain() { int n; bool first = true; while (scanf("%d", &n) != EOF) { int all = 0, part = 0; double r = n - 0.5; for (int x = 0; x < n; x++) for (int y = 0; y < n; y++) { double d1 = getDis(x, y), d2 = getDis(x + 1, y + 1);//左下角、右下角 if (d2 <= r) all++; elseif (d1 < r) part++; }
if (first) first = false; elseputchar('\n');
printf("In the case n = %d, %d cells contain segments of the circle.\n", n, part*4); printf("There are %d cells completely contained in the circle.\n", all*4); }