Follows 356.c (Total 31 lines):

/* @JUDGE_ID:4461XX 356 C */
/* A */
#include<stdio.h>
#include<math.h>
void run( int n )
{
	int in=0 , on = 0 ;
	double i , j , r=n-0.5 , disl , disr ;
	for( i=0.0 ; i<n ; i++ )
		for( j=0.0 ; j<n ; j++ ){
			disl = sqrt( i*i+j*j ) ;
			disr = sqrt( (i+1)*(i+1)+(j+1)*(j+1) ) ;
			if( disl<r && disr>r ) on++ ;
			if( disl<r && disr<r ) in++ ;
		}
	/* on = 2 * n - 1 ;*/
	printf( "In the case n = %d, %d cells contain segments of the circle.\n" , n , 4*on ) ;
	printf( "There are %d cells completely contained in the circle.\n" , 4*in ) ;
}
void main( void )
{
	int n ;
	int firstOutput=1;
	while( scanf( "%d" , &n ) == 1 ){
		if( firstOutput )
			firstOutput = 0;
		else
			putchar( '\n' );
		run( n ) ;
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com