Problem
Chef Ada is training to defend her title of World Chess Champion.
To train her calculation skills, Ada placed a king on a chessboard. Remember that a chessboard has rows and columns (for the purposes of this problem, both the rows and the columns are numbered through ); let's denote the square in row and column by . A king on a square can move to another square if and only if .
Ada placed her king on the square . Now, she is counting the number of squares that can be visited (reached) by the king in at most moves. Help Ada verify her answers.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first and only line of each test case contains three space-separated integers , and .
Output
For each test case, print a single line containing one integer — the number of squares the king can visit.
Constraints
Sample 1:
1 1 3 1
6
Explanation:
Example case 1: The king can stay on its original square or move to one of the squares circled in the following figure.

Program :
#include <stdio.h>
int main(void) {
// your code goes here
int t;
scanf("%d",&t);
while(t--)
{
int p,q,k,ans=0,i,j;
scanf("%d %d %d",&p,&q,&k);
for(i=1;i<=8;i++)
{
for(j=1;j<=8;j++)
{
if(pow((i-p),2)<=pow(k,2)&&pow((j-q),2)<=pow(k,2))
{
ans++;
}
}
}
printf("%d\n",ans);
}
return 0;
}
0 Comments