UVa 155 All Squares
1
#include<stdio.h>
2 #include<stdlib.h>
3 #include<iostream>
4 #include<algorithm>
5 using
namespace std;
6 int x,y;
7 int square(int cntx,int cnty,int k)
8 {
9 if( k <= 0 )
10 return 0;
11 int left=cntx-k,right=cntx+k,up=cnty+k,botton=cnty-k;
12 if(left<0 || right <0 || up<0 || botton<0 ) return 0;
13
14 int num=0;
15 if(x>=left && x<=right && y<=up && y>=botton)
16 {
17 num++;
18 }
19 num+=square(left,up,k/2);
20 num+=square(right,up,k/2);
21 num+=square(left,botton,k/2);
22 num+=square(right,botton,k/2);
23
24 return num;
25 }
26 int main()
27 {
28 int k;
29 while(cin>>k>>x>>y && (k!=0 || x!=0 || y!=0) )
30 {
31 printf("%3d\n",square(1024,1024,k));
32 }
33
34 return 0;
35 }
留言
張貼留言