Title: Draw a circle with a diameter of 2n-1 in the middle of a 2n*2n grid, asking the inner lattice of the circle and the number of squares that intersect the circle.
Analysis: Calculate geometry. The intersection point (Xi,yi) is calculated and divided by the horizontal axis of each integer.
Ceil (Yi)-ceil (yi-1) is the number of intersecting squares per column, and floor (Yi) is the number of squares in each column.
Description: Note accuracy (⊙_⊙).
#include <algorithm> #include <iostream> #include <cstdlib> #include <cstring> #include < Cstdio> #include <cmath>using namespace Std;int main () {int n,in,on,count = 0;while (cin >> N) {in = 0,on = 0 ;d ouble r,l = n-0.5;for (int i = 1; i < n; + + i) {r = sqrt ((n-0.5) * (n-0.5)-i*i); on + = ((int) (L+1-1E-12)-(int) (r+1-1 e-12) +1) <<2;in + = ((int) (r+1e-12)) <<2;l = R;} on + = ((int) (L+1-1E-10)) <<2;if (count + +) printf ("\ n");p rintf ("in the case n =%d,%d cells contain segments of the Circle.\n ", N,on);p rintf (" There is%d cells completely contained in the circle.\n ", in);} return 0;}
UVa 356-square pegs and Round Holes