// UVa 356 - Square Pegs And Round Holes
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
int main() {
int n, t = 0;
while (cin >> n) {
double r = n - 0.5;
double b4 = r;
int inside = 0, partial = 0;
inside = 0;
for (int i = 1; i < n; i++) {
double now = sqrt(r * r - i * i);
inside += floor(now);
partial += ceil(b4) - floor(now);
b4 = now;
}
partial += ceil(b4);
inside *= 4;
partial *= 4;
t++;
if (t > 1)
printf("\n");
printf("In the case n = %d, %d cells contain segments of the circle.\n", n, partial);
printf("There are %d cells completely contained in the circle.\n", inside);
}
return 0;
}
Sunday, June 7, 2015
UVa 356 - Square Pegs And Round Holes
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment