Created
February 3, 2011 10:40
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#define SIDE_X_AND_Y 2048 | |
int squares( int k, int cenx, int ceny, int surx, int sury ) | |
{ | |
if( k <= 0 ) | |
return 0; | |
int left = cenx - k; | |
int right = cenx + k; | |
int top = ceny - k; | |
int bottom = ceny + k; | |
if( left < 0 || right < 0 || top < 0 || bottom < 0 ) | |
return 0; | |
int result = 0; | |
if( surx >= left && surx <= right && sury <= bottom && sury >= top ) | |
result++; | |
result += squares( k/2, left, top, surx, sury ); | |
result += squares( k/2, right, top, surx, sury ); | |
result += squares( k/2, left, bottom, surx, sury ); | |
result += squares( k/2, right, bottom, surx, sury ); | |
return result; | |
} | |
int main() | |
{ | |
int k, surx, sury; | |
while( scanf( "%d%d%d", &k, &surx, &sury ) != EOF ) | |
{ | |
if( k == 0 && surx == 0 && sury == 0 ) | |
break; | |
int cenx = 1024, ceny = 1024; | |
printf( "%3d\n", squares( k, cenx, ceny, surx, sury ) ); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment